Is it possible to animate the dismissal of a modal...
# compose
Is it possible to animate the dismissal of a modal bottom sheet when using
? (or if the user clicks the back button, or clicks on something that calls
) Currently the animation only plays if the user clicks on the scrim or drags the sheet down.
It seems I could do this if I created my own
but I have the notion that’s not recommended
Or is it fine to do this?
Copy code
val modalBottomSheetState = rememberModalBottomSheetState(
      initialValue = ModalBottomSheetValue.Hidden,
      skipHalfExpanded = true,
    val bottomSheetNavigator = remember(modalBottomSheetState) {
      BottomSheetNavigator(sheetState = modalBottomSheetState)
Then I could just call
on the sheet state
When popping the bottom sheet destination off the back stack, ideally, we would animate regularly. There's an issue in the upstream Material component though where most of the time, the
call will be cancelled when we update the sheet's content to be empty. Using
means that the state will pretty much instantly snap to the requested anchor, resulting in no animation. Ideally, we'd be hiding the sheet first and then changing the content; I'll try to put up a PR. There's also an open issue in the Accompanist repo 🙂
If you just call
there's a good chance that the navigator and the sheet state get out of sync. That constructor will be made internal soon, too.