示例代码:
@Composable fun BottomSheetExample() { var showBottomSheet by remember { mutableStateOf(false) } val scrollState = rememberScrollState()
BottomSheetScaffold( sheetContent = { /* Bottom sheet content */ }, sheetPeekHeight = 0.dp, scaffoldState = rememberBottomSheetScaffoldState( bottomSheetState = BottomSheetState( initialValue = BottomSheetValue.Collapsed ) ) ) { Button(onClick = { showBottomSheet = true }) { Text(text = "Open bottom sheet") }
if (showBottomSheet) {
LaunchedEffect(Unit) {
with(FrameManager.defaultContext) {
val lightTheme = true // Change this based on app preference
UpdateTransition(lightTheme, label = "Theme").apply {
val isOpening = CurrentBooleanPropKey
targetState(switch = lightTheme)
val fromHeight = if (lightTheme) 600.dp else 350.dp
val toHeight = if (lightTheme) 350.dp else 600.dp
val transition = idx.transitionDefinition {
state(false) { this[Modifier.height] = fromHeight }
state(true) { this[Modifier.height] = toHeight }
transition(isOpening to true) {
Modifier.height using tween(
durationMillis = 500
)
}
transition(isOpening to false) {
Modifier.height using tween(
durationMillis = 500
)
}
}
val state = AnimState(false)
snapshotFlow { state.value }
val endState = transition.createAnimationState(
targetValue = switch,
onStateChangeFinished = {
state.value = switch
}