react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

[v2] BottomSheetModal close function has inconsistent behavior when snap points array is hard coded

Open IzaELK opened this issue 3 years ago • 2 comments

Bug

When snapPoints is provided to BottomSheetModal component as props with a constant close function will always close BottomSheetModal.

const snapPoints = [300, 500];

const MyWorkingComponent = () => {
return (
    <BottomSheetModal
      snapPoints={snapPoints}
      ref={bottomSheetModalRef}
      dismissOnPanDown={false}
      backdropComponent={renderBackdrop}
    >
      <Button onPress={()=>{bottomSheetModalRef.current?.close()}} >Close Modal</Button>
    </BottomSheetModal>
  );
}

However when snapPoints is provided as an hard coded array, close function doesn’t work around 50% of the time.

const MyRandomComponent = () => {
return (
    <BottomSheetModal
      snapPoints={[300, 500]}
      ref={bottomSheetModalRef}
      dismissOnPanDown={false}
      backdropComponent={renderBackdrop}
    >
      <Button onPress={()=>{bottomSheetModalRef.current?.close()}} >Close Modal</Button>
    </BottomSheetModal>
  );
}

Environment info

Library Version
@gorhom/bottom-sheet ^2
react-native 0.65.0
react-native-reanimated 1.13.0
react-native-gesture-handler 1.10.3

Steps To Reproduce

  1. Create component with hard coded spanPoints
  2. Display component at application mount
  3. Try to close BottomSheetModal with close button.
  4. Kill app if bug doesn’t occur and try again (it will occur after 3 or 4 tries)

Describe what you expected to happen:

  1. BottomSheetModal closes each time I call close function.

Reproducible sample code

const MyRandomComponent = () => {
return (
    <BottomSheetModal
      snapPoints={[300, 500]}
      ref={bottomSheetModalRef}
      dismissOnPanDown={false}
      backdropComponent={renderBackdrop}
    >
      <Button onPress={()=>{bottomSheetModalRef.current?.close()}} >Close Modal</Button>
    </BottomSheetModal>
  );
}

IzaELK avatar Jul 12 '22 13:07 IzaELK

With BottomSheetModal

Use bottomSheetModalRef.current?.dismiss()

Instead of bottomSheetModalRef.current?.close()

This is working for me like a charm.

ursnj avatar Jul 13 '22 03:07 ursnj

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 12 '22 09:08 github-actions[bot]

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

github-actions[bot] avatar Aug 17 '22 09:08 github-actions[bot]