raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.22k stars 133 forks source link

BottomSheet opening delay #676

Open jibe-n opened 2 months ago

jibe-n commented 2 months ago

Hi! 👋

I'm currently using compose-destinations 2.1.0-beta11 and I noticed a slight delay when a bottom sheet is opened.

This delayed animation only happens when I pass a customised sheet state to my BottomSheetNavigator instead of doing rememberBottomSheetNavigator(), like so:

val sheetState = rememberModalBottomSheetState(
    initialValue = ModalBottomSheetValue.Hidden,
    confirmValueChange = { true },
    skipHalfExpanded = true
)
val bottomSheetNavigator = remember { BottomSheetNavigator(sheetState) }
navController.navigatorProvider += bottomSheetNavigator

After digging a bit, I noticed that the ModalBottomSheetDefaults.AnimationSpec from androidx.compose.material (which defaults the animationSpec of rememberModalBottomSheetState()) was recently changed from a SpringSpec() to a tween() animation, leading to this delay. For more context, this change was made to resolve this issue: https://issuetracker.google.com/issues/285847707

As a temporary solution, I just pass a SpringSpec() to the animationSpec parameter of the rememberModalBottomSheetState() constructor which removes this delay, but I was wondering if that's something you would be able to look into because I think this problem might happen in future releases.

I'm not sure why this is happening, I made 2 sample projects that respectively use androidx.compose.material3:material3:1.3.0-rc01 for one and androidx.compose.material:material:1.7.0-rc01 for the other (which both use the newly changed tween() animationSpec in their bottom sheet implementation) to see if that delay exists but none of them have the issue.

You can reproduce this delayed behaviour by simply adding a tween() animationSpec in the PlaygroundScaffold.kt file when declaring the bottom sheet navigator.

haluzpav commented 2 months ago

To make it more obvious, passing spring() here brings back the old behavior and removes the delay.

val sheetState = rememberModalBottomSheetState(
    initialValue = ModalBottomSheetValue.Hidden,
    animationSpec = spring(),
)
val bottomSheetNavigator = remember(sheetState) {
    BottomSheetNavigator(sheetState = sheetState)
}

or if you don't need to override the sheet state, just

val bottomSheetNavigator = rememberBottomSheetNavigator(
    animationSpec = spring(),
)