react-native-bottom-sheet icon indicating copy to clipboard operation
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

Open mkizesov opened this issue 7 months ago • 2 comments

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 onClose callback with some log or Alert operation
  • Test that when screen containing BottomSheet is mounted, onClose is 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


mkizesov avatar May 05 '25 20:05 mkizesov

tested this on latest release, and both iOS & Android did not call on close

gorhom avatar Jun 03 '25 19:06 gorhom

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)

mkizesov avatar Jun 03 '25 19:06 mkizesov

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.

brentforder avatar Jun 27 '25 00:06 brentforder

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.

github-actions[bot] avatar Jul 27 '25 09:07 github-actions[bot]

Given my experience (https://snack.expo.dev/ncSmfPqCKNptLjqQIQfYP) and the comment above, the problem is still not solved.

mkizesov avatar Jul 27 '25 11:07 mkizesov

I have the same issue but bo issues on Android, only ios: v5.1.8

Willham12 avatar Jul 28 '25 06:07 Willham12

snapPoints={['50']} works fine but snapPoints={['49']} not

Willham12 avatar Jul 28 '25 13:07 Willham12

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

sharifhh avatar Jul 29 '25 22:07 sharifhh

I was able to prevent the onClose callback fires with animateOnMount={false} With your patch im missing the open animation.

Willham12 avatar Jul 30 '25 00:07 Willham12

@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

matiaswastaken avatar Jul 30 '25 13:07 matiaswastaken

check the comments here please https://github.com/gorhom/react-native-bottom-sheet/pull/2387

sharifhh avatar Jul 30 '25 17:07 sharifhh

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.

github-actions[bot] avatar Aug 30 '25 09:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 04 '25 09:09 github-actions[bot]