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

[v4] Crash on reduced motion #1866

Open
mihaibulic2 opened this issue Jun 21, 2024 · 0 comments
Open

[v4] Crash on reduced motion #1866

mihaibulic2 opened this issue Jun 21, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mihaibulic2
Copy link

Bug

Two things:

  1. the change in 4.6.3 to handle reduced animations isn't complete: if a rerender happens during dismissal, the bottom sheet jitters and appears again; eg call setSomeState right when you call dismiss on your modal ref - make sure you use someState in the bottom sheet content UI)
  2. the approach used in that commit also causes a crash: "TypeError: Cannot assign to read-only property 'reduceMotion'" (on Android)

The way I found to workaround it, which maybe could be lifted into the bottom-sheet codebase is to set animateOnMount={!reduceMotionEnabled}.

That on it's own doesn't work though! If you just do that then the modal can only be dismissed via the ref one time. To work around that, I did this:

<BottomSheetModal
  animateOnMount={!reduceMotionEnabled}
  key={`bottom-sheet-modal-${bottomSheetBumpKey}`}
  onDismiss={() => {
    if (reduceMotionEnabled) {
      setBottomSheetBumpKey((existing) => existing + 1);
    }
  }}
  ...
>

That's pretty ugly, but essentially it forces the BottomSheetModal to rerender whenever we dismiss, giving us a fresh ref. Ideally there is a more proper fix that can be done inside the bottom-sheet lib to prevent this?

Environment info

Library Version
@gorhom/bottom-sheet 4.6.3
react-native 0.74.1
react-native-reanimated 3.11.0
react-native-gesture-handler 2.16.2

Steps To Reproduce

  1. update to 4.6.3
  2. turn on reduce animations on android
  3. open bottom sheet modal

Describe what you expected to happen:

  • don't crash!

Reproducible sample code

@mihaibulic2 mihaibulic2 added the bug Something isn't working label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant