Lisandro Di Meo
11/10/2022, 2:54 PMScaffold(/*...*/){
NavGraph(/*...*/)
}
Shouldn't it be better if we face it with a different approach, something like:
NavGraph(/*...*/){
composable(A){ Scaffold(...) }
composable(B){ ModalBottomSheet(...) }
...
}
Also by using the previous approach, we shouldn't have to move the scaffold state from one place to other, and each screen will know its own traits.dorche
11/10/2022, 6:01 PMLisandro Di Meo
11/10/2022, 6:05 PMModalBottomSheetLayout(
sheetState = sheetState,
sheetShape = RoundedCornerShape(topStart = Dimen16dp, topEnd = Dimen16dp),
sheetContent = {
ModalBottomSheet(
coroutine = coroutineScope,
sheetState = sheetState,
isExpanded = true,
header = bottomSheetState.value?.header,
body = bottomSheetState.value?.body,
footer = bottomSheetState.value?.footer
)
}
) {
Scaffold(
scaffoldState = scaffoldState,
snackbarHost = {
SnackbarHost(hostState = snackbarHostState) { data ->
Snackbar(actionColor = Color(0xFFBB86FC), snackbarData = data)
}
},
topBar = {
if (appBarState.value?.enabled == true) {
TopAppBar(appBarViewModel)
}
},
drawerContent = if (drawer.drawerState.value == null) {
null
} else {
{ drawer.drawerState.value?.let { drawer(drawerState = it) } }
},
bottomBar = {
BottomNavigation(
navHostController = navController,
viewModel = appBarViewModel,
dashboardNavigationItems
)
},
floatingActionButton = {
if (barsState.value!!.isVisible) {
FloatingActionButton(
shape = CircleShape,
contentColor = Color.White,
onClick = {
navController.navigate(...) {
popUpTo(...) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
backgroundColor = Mirage
) {
Icon(painterResource(id = DashboardNavigationItem.QR.iconId), "QR")
}
}
},
floatingActionButtonPosition = FabPosition.Center,
isFloatingActionButtonDocked = true,
content = {
Column(modifier = Modifier.padding(it)) {
Navigation(
navController,
snackbarHelper,
appBarViewModel,
accountCreationViewModel,
newPasswordViewModel,
dashboardViewModel,
accessMenuViewModel,
bottomSheetViewModel,
qrViewModel,
drawer,
analytics,
onLoginSucceed = {
expirationPolicy.attachToLifecycle()
},
onLogOutSucceed = {
expirationPolicy.detachFromLifecycle()
},
onFinish = onFinish
)
}
}
)
}
Lisandro Di Meo
11/10/2022, 6:05 PMLisandro Di Meo
11/10/2022, 6:06 PMdorche
11/10/2022, 6:29 PMLisandro Di Meo
11/10/2022, 6:37 PMdorche
11/10/2022, 9:29 PMLisandro Di Meo
11/11/2022, 1:05 PMdorche
11/11/2022, 1:39 PMval showFab = when destination {
ScreenA -> true
ScreenB -> false
}
So in some basic scenarios you won't need to tell it to hide/show all the time. Hard to say if that's useful without knowing your app.
What do you use the bottomSheet for? Could you move it into a nested Scaffold defined per screen?Lisandro Di Meo
11/14/2022, 4:00 PMval showSheet = when destination ...
And each destination that has to show the bottom sheet, should emit its desired content like a callback
composable(A) {
Column(...){
// ScreenA
}
sheetContent = {
SheetContentForA()
}
}dorche
11/14/2022, 4:37 PMScaffold(
// dont set sheet here
){
NavGraph(/*...*/){
composable(A){
ScreenA()
}
composable(B){ ScreenB() }
...
}
}
@Composable
fun ScerenA() {
Scaffold(
// sheet here so now it's part of the "screen/destination"
) {
}
}
Lisandro Di Meo
11/14/2022, 4:49 PMdorche
11/14/2022, 4:57 PMLisandro Di Meo
11/14/2022, 5:37 PM