react-native-bottom-sheet
react-native-bottom-sheet copied to clipboard
[Bug]: `onClose` callback is called on mount when initial index is set to `-1` and BottomSheet is not presented
Version
v5
Reanimated Version
v3
Gesture Handler Version
v2
Platforms
Android
What happened?
onClose callback is being called on the first mount of BottomSheet even if initial index={-1}.
https://github.com/gorhom/react-native-bottom-sheet/blob/65b5dc03e673c25b3b41af954e1f13fe7668a339/src/components/bottomSheet/BottomSheet.tsx#L1561
Reproduction steps
- Add a regular bottom sheet to the screen
- Set index=-1
- Provide test
onClosecallback with some log or Alert operation - Test that when screen containing BottomSheet is mounted,
onCloseis called, even if BottomSheet is not presented to a user
Or just open the Snack and you'll see that onCloseCalled state var is set to 'true' on first load (initially it's 'false' and onClose is setting it 'true')
Reproduction sample
https://snack.expo.dev/CagMBytOalvWOV2MeZCR5
Relevant log output
tested this on latest release, and both iOS & Android did not call on close
hmm I've upgraded to v5.1.5 and reproduced both in Android emulator locally and in the Snack (both iOS and Android) https://snack.expo.dev/ncSmfPqCKNptLjqQIQfYP (upd: updated link)
The same is happening for me with v5.1.6, on Android 15 hardware (Pixel 8)
<BottomSheet
ref={bottomSheetRef}
index={-1}
snapPoints={snapPoints}
enableDynamicSizing={false}
enableOverDrag={false}
onChange={(index, position, snapPointType) => infoSheetEventAdapter.handleOnChange(index, position, snapPointType)}
onClose={() => infoSheetEventAdapter.handleOnClose()}
...
onClose() fires aggressively, and without any user interaction:
- on BottomSheet mount.
- at other unexpected times when neither the snap index or the BottomSheetView's layout height has changed.
- whether or not the snap index is updated via snapToIndex or control of the index property.
I haven't found a way to control it. I debounce the onClose events in my adapter layer, with a check on whether the content height has changed. I'm guessing that it's related to react-native-reanimated or something else at the native level.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Given my experience (https://snack.expo.dev/ncSmfPqCKNptLjqQIQfYP) and the comment above, the problem is still not solved.
I have the same issue but bo issues on Android, only ios: v5.1.8
snapPoints={['50']} works fine but snapPoints={['49']} not
https://github.com/gorhom/react-native-bottom-sheet/issues/2386 https://github.com/gorhom/react-native-bottom-sheet/pull/2387
@gorhom+bottom-sheet+5.1.8.patch
try these
I was able to prevent the onClose callback fires with animateOnMount={false}
With your patch im missing the open animation.
@Willham12 @sharifhh Yeah same, when applying that patch the open animation is just broken
EDIT:
And I have the exact same issue as @Willham12, snappoint 49% doesnt work but 50% works, if i set animateOnMount={false}Â then everything works but there's no smooth animation when opening the bottom sheet
check the comments here please https://github.com/gorhom/react-native-bottom-sheet/pull/2387
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.