react-native-bottom-sheet: [Bug]: Changing FlatList data causes bottomsheet to close
Version
v5
Reanimated Version
v3
Gesture Handler Version
v2
Platforms
iOS
What happened?
If enableDynamicSizing is true and index is set to -1 then when the data for a BottomSheetFlatList changes the open index gets set to -1 ie. closes the bottom sheet.
- This does no occur with dynamic sizing off
- This does not occur if the index prop is missing/set to something other than -1
Reproduced on ios, untested on web/android
Reproduction steps
Using the reproduction example:
- Press ‘open’ to open the bottom sheet
- Press ‘add’ to modify the flatlist data
- See the bottom sheet closes
Reproduction sample
https://snack.expo.dev/@geraintfisher/bottom-sheet-bug
Relevant log output
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 7
- Comments: 25 (2 by maintainers)
I think the problem lies in how evaluatePosition calculates the bottom sheet’s next position during re-renders. The logic inadvertently snaps the sheet to -1 (closed state) but it should snap to currentIndex. Fixed it by adding a check:
Might help those that are having problems on iOS.
Having the exact same issue that @Simonas-Juska mentioned. Whenever a rerender happens (for example, if we do something like
onChange={setSnapIndex}or something similar) the bottom sheet closes the first time it’s opened and afterwards it works correctly. After some in depth debugging of the flow I’ve found that doing the following patch:fixes this issue. Not entirely sure on which commit introduces it, but it’s likely a side-effect of something else. I believe the underlying reason is related to the fact that upon first opening, this line gets hit and as a (probably) unwanted consequence of this change (or one of the related ones to it) we get an automatic close as the position is not yet updated.
I unfortunately did not have the time to debug in more depth but I hope this might be helpful for you @gorhom - please let me know if I can provide any additional help !
Note: In my circumstance, it does not at all matter whether
enableDynamicSizingis set totrueorfalse- but rather the rerender causes the issue.Note 2: The issue is reproducible for all
5.x.xversions.Same issue here, although not specifically related to FlatList. Also happens with
BottomSheetViewwhen component re-renders. iOS only.work!! @arsotech thanks!
i was follow this. Go in to /node_modules/@gorhom/bottom-sheet/src/components/bottomSheet/BottomSheet.tsx and using patch-packages to save edit in nodemoules and i work for me! @arsotech thanks bro!
That indeed fixed it. Thanks @ustuncem for looking into it.
I spend a lot of hours to debug, this helped me
Patch is not working for me unfortunately. New architecture / ios. Patch causes the sheet (in close mode index = -1) to render momentarily over the screen before it closes to it’s default position.
Same issue here, patch from @isekovanic is working, thanks 😃
Can we have a new release?