Last active
February 12, 2025 11:40
-
-
Save Skeptick/d1be0b726db99b82987bab0529b94f2c to your computer and use it in GitHub Desktop.
rememberBottomSheetChild
This file contains hidden or 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 <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 = child | |
} | |
return bottomSheetChild | |
} |
This file contains hidden or 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 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