react-native-bottom-sheet: [v4] BottomSheetBackdrop does not close BottomSheet onTouch
Bug
BottomSheetBackdrop does not close BottomSheet onTouch even with pressBehavior=“close” props. I tried several methods but I can’t get an onPress event working on the BottomSheetBackdrop component either.
Environment info
| Library | Version |
|---|---|
| @gorhom/bottom-sheet | 4 |
| react-native | 0.69.6 |
| react-native-reanimated | ~2.9.1 |
| react-native-gesture-handler | ~2.5.0 |
Steps To Reproduce
See code below.
Describe what you expected to happen:
- Clicking on the Backdrop closes the BottomSheet
Reproducible sample code
const tailwind = useTailwind()
const bottomSheetRef = useRef<BottomSheet>(null);
const snapPoints = useMemo(() => ['15%', '30%'], []);
const handleSheetChanges = useCallback((index: number) => {
console.log('handleSheetChanges', index);
}, []);
useEffect(() => {
if (open) {
bottomSheetRef.current?.expand();
}
else {
bottomSheetRef.current?.close();
}
}, [open])
const renderBackdrop = useCallback(
props => (
<BottomSheetBackdrop
{...props}
pressBehavior='close'
/>
),
[]
);
console.log({ MyBottomSheet: { open } })
return (
<BottomSheet
ref={bottomSheetRef}
index={-1}
snapPoints={snapPoints}
onChange={handleSheetChanges}
enablePanDownToClose
backdropComponent={renderBackdrop}
backgroundComponent={({ style }) => <View style={[style, tailwind('bg-slate-800')]} />}
enableOverDrag
enableHandlePanningGesture
>
<View />
</BottomSheet>
)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 16
This works for me:
Did you try <GestureHandlerRootView style={{ flex: 1 }}>{/* content */}</ GestureHandlerRootView> ?
@yaaamin it still doesn’t seem to work even with
GestureHandlerRootViewat the root in App.jsFor anyone who is still looking for fixes for this issue, just wrap your App.js component with the following
export default function App() { return <GestureHandlerRootView>{/* content */}</GestureHandlerRootView>; }_extracted from https://docs.swmansion.com/react-native-gesture-handler/docs/1.10.3/_
These should be the default values. I imagine at least 90% of people adding a backdrop just want this native-like behaviour.
Solved with update MainActivity.java with RNGestureHandlerEnabledRootView and wrapped JS code with view < GestureHandlerRootView>
See reference https://docs.swmansion.com/react-native-gesture-handler/docs/guides/migrating-off-rnghenabledroot
Is there anyway we can overcome this issue for people using Expo Managed Workflow?