Created
December 5, 2021 16:39
-
-
Save enyciaa/5c71c81b46815c802d26a68b8cf67406 to your computer and use it in GitHub Desktop.
screen-template-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ScreenTemplate( | |
screenBackgroundColor: Color = MaterialTheme.colors.surface, | |
screenState: ScreenState, | |
loadedState: @Composable () -> Unit, | |
screenToolbarViewState: ScreenToolbarViewState? = null, | |
screenCallToActionViewState: ScreenCallToActionViewState? = null, | |
onCallToActionClicked: () -> Unit = { }, | |
) { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = screenBackgroundColor, | |
) { | |
Box { | |
Column { | |
if ( | |
screenToolbarViewState != null | |
) { | |
OurToolbar(screenToolbarViewState = screenToolbarViewState) | |
} | |
ScreenContent( | |
modifier = Modifier.fillMaxSize(), | |
screenState = screenState, | |
loadedState = loadedState, | |
) | |
} | |
if (screenCallToActionViewState != null) { | |
CallToAction( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(horizontal = 40.dp) | |
.padding(bottom = 40.dp) | |
.align(Alignment.BottomCenter), | |
screenCallToActionViewState = screenCallToActionViewState, | |
onClicked = onCallToActionClicked, | |
) | |
} | |
} | |
} | |
} | |
@Composable | |
private fun ScreenContent( | |
modifier: Modifier = Modifier, | |
screenState: ScreenState, | |
loadedState: @Composable () -> Unit, | |
) { | |
Box(modifier = modifier) { | |
when (screenState) { | |
is ScreenState.Loading -> | |
Box( | |
modifier = Modifier.fillMaxSize(), | |
contentAlignment = Alignment.Center, | |
) { | |
OurLoadingIndicator() | |
} | |
is ScreenState.Error -> | |
Box( | |
modifier = Modifier.fillMaxSize(), | |
contentAlignment = Alignment.Center, | |
) { | |
OurErrorTemplate(screenErrorViewState = screenState.screenErrorViewState) | |
} | |
is ScreenState.Loaded -> { | |
Box(modifier = Modifier.fillMaxSize()) { | |
loadedState() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment