Adriano Celentano
04/20/2023, 3:50 PMModalBottomSheetState
in the ViewModel ?
For now we do some ugly syncing with a vm state and the ModalBottomSheetState
in the Composable
val modalBottomSheetState =
rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true)
val isVisible by viewModel.isVisible.collectAsState()
// if the bottom sheet state is changed by dragging down we need to sync it with our vm state
// we have the state in the vm to control it from outside of the Composable
LaunchedEffect(key1 = modalBottomSheetState.isVisible) {
if (!modalBottomSheetState.isVisible && isVisible) viewModel.hide()
}
LaunchedEffect(key1 = isVisible) {
when {
isVisible -> modalBottomSheetState.show()
else -> modalBottomSheetState.hide()
}
}
return modalBottomSheetState
After updating Compose this results in a recompositon loopColton Idle
04/20/2023, 5:25 PMmattinger
04/20/2023, 8:54 PMModalBottomSheetState(
initialValue = initialValue,
animationSpec = animationSpec,
isSkipHalfExpanded = skipHalfExpanded,
confirmStateChange = confirmStateChange
)
Colton Idle
04/21/2023, 5:11 AMManuel Vivo
04/21/2023, 6:42 AMviewModelScope
. We documented the caveat here: https://developer.android.com/jetpack/compose/state-hoisting#caveat
oYou canAdriano Celentano
04/21/2023, 6:57 AMcloseDrawer
from a Fragment as i don't have the right uiScope there ?
at least that is what happens when i pass a LifecycleScope from my Fragment
A MonotonicFrameClock is not available in this CoroutineContext