Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BottomSheet opening delay #676

Open
jibe-n opened this issue Aug 24, 2024 · 1 comment
Open

BottomSheet opening delay #676

jibe-n opened this issue Aug 24, 2024 · 1 comment

Comments

@jibe-n
Copy link

jibe-n commented Aug 24, 2024

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
Copy link

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(),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants