Skip to content

Instantly share code, notes, and snippets.

@enyciaa
Created December 5, 2021 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enyciaa/5c71c81b46815c802d26a68b8cf67406 to your computer and use it in GitHub Desktop.
Save enyciaa/5c71c81b46815c802d26a68b8cf67406 to your computer and use it in GitHub Desktop.
screen-template-8
@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