Tapan Desai
09/15/2023, 5:15 AMIan Lake
09/15/2023, 5:27 AMascii
09/15/2023, 5:30 AMascii
09/15/2023, 5:31 AMTapan Desai
09/15/2023, 5:37 AMother than allowing opening sheets from a navigator?@ascii that’s what we are using it for
ascii
09/15/2023, 5:53 AMvar showSheet by remember { mutableStateOf(false) }
Button({ showSheet = true })
if (showSheet) ModalBottomSheet({ showSheet = false }) {
SheetContent()
}
or automatically, for example to display an error:
var error by remember { mutableStateOf<String?>(null) }
MainContent(onError = { error = it })
if (error) ModalBottomSheet({ error = null }) {
SheetContent()
}
Of course, you can also pass your own ModalBottomSheetState if you want to do more than just show/hide (e.g. partial expand).Ian Lake
09/15/2023, 2:19 PMLifecycle
, ViewModels, and saved state that is tied to the existence of the bottom sheet (i.e., gets cleaned up when the bottom sheet is dismissed)Ian Lake
09/15/2023, 2:21 PMDialog
in that a lot of the time, you don't actually need all of that and can just embed it in your destination itself. We make this same point of "do you really need it as a separate destination" in the docs on dialog destinations: https://developer.android.com/reference/kotlin/androidx/navigation/compose/package-summary#(androidx.navigation.NavGraphBuilder).dialog(kotlin.String,kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.window.DialogProperties,kotlin.Function1)jossiwolf
09/18/2023, 1:26 PM