Created
October 30, 2024 16:39
-
-
Save Skeptick/d1be0b726db99b82987bab0529b94f2c to your computer and use it in GitHub Desktop.
rememberBottomSheetChild
This file contains 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 = null | |
} else { | |
bottomSheetChild = child | |
} | |
} | |
return bottomSheetChild | |
} |
This file contains 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