Skip to content

Instantly share code, notes, and snippets.

@Skeptick
Created October 30, 2024 16:39
Show Gist options
  • Save Skeptick/d1be0b726db99b82987bab0529b94f2c to your computer and use it in GitHub Desktop.
Save Skeptick/d1be0b726db99b82987bab0529b94f2c to your computer and use it in GitHub Desktop.
rememberBottomSheetChild
@Composable
fun <C : Any, T : Any> ChildSlot<C, T>.rememberBottomSheetChild(onDismiss: suspend () -> Unit): Child.Created<C, T>? {
var bottomSheetChild: Child.Created<C, T>? by remember { mutableStateOf(child) }
LaunchedEffect(child) {
if (child == null) {
onDismiss()
bottomSheetChild = null
} else {
bottomSheetChild = child
}
}
return bottomSheetChild
}
@Composable
fun Sample() {
val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val bottomSheetChild = bottomSheetSlot.rememberBottomSheetChild(
onDismiss = {
if (bottomSheetState.isVisible) {
bottomSheetState.hide()
}
}
)
bottomSheetChild?.let {
ModalBottomSheet(...)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment