react-native-bottom-sheet
react-native-bottom-sheet copied to clipboard
[v4] | [v2] BottomSheetModal Not Closing onPress outside / cant slide the bottomsheet , touches working only inside bottomsheet
Bug
Environment info
| Library 4.1.5 | |
|---|---|
| @gorhom/bottom-sheet 4.1.5 | |
| react-native 2.8.0 | |
| react-native-reanimated 0.67.4 | |
| react-native-gesture-handler 2.4.1 |
Reproducible sample code
const displayBottomSheet = useCallback(() => {
bottomSheetModalRef.current?.expand();
}, []);
const hideBottomSheet = useCallback(() => {
bottomSheetModalRef.current?.close();
}, []);
<TouchableOpacity onPress={displayBottomSheet}>
<Text>touch me</Text>
</TouchableOpacity>
<BottomSheetModalProvider>
<BottomSheetModal
backdropComponent={renderBackdrop}
ref={bottomSheetModalRef}
index={0}
snapPoints={snapPoints}>
<BottomSheetScrollView
style={{flex: 1}}>
<TouchableOpacity onPress={hideBottomSheet}>
<Text>touch me</Text>
</TouchableOpacity>
</BottomSheetScrollView>
</BottomSheetModal>
</BottomSheetModalProvider>
Did you solve this? Having the same issue.
@YounesKHENIFER before closing, if you found the solution then you should add it, the issue is just saying some problem but no one has provided the solution.
I handled it using some extra code
Assume AppFeatureBottomSheet you have added all the require code for BottomSheetModal
import { BottomSheetModal } from '@gorhom/bottom-sheet'
import React, { useRef } from 'react'
import { StyleSheet, TouchableWithoutFeedback, View } from 'react-native'
import AppFeatureBottomSheet from './AppFeatureBottomSheet'
interface AppFeatureProps {
visible: boolean
onDismiss: () => void
}
export default function AppFeature({ visible, onDismiss }: AppFeatureProps) {
const bottomSheetModalRef = useRef<BottomSheetModal>(null)
if (visible) {
setTimeout(() => {
bottomSheetModalRef.current?.present()
bottomSheetModalRef.current?.expand()
}, 100)
}
return (
<>
{visible && (
<TouchableWithoutFeedback
onPress={() => {
bottomSheetModalRef.current?.dismiss()
onDismiss()
}}
>
<View style={styles.overlay}>
<AppFeatureBottomSheet
bottomSheetModalRef={bottomSheetModalRef}
onDismiss={onDismiss}
/>
</View>
</TouchableWithoutFeedback>
)}
</>
)
}
const styles = StyleSheet.create({
overlay: {
height: '100%',
position: 'absolute',
top: 0,
left: 0,
right: 0,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
})
i have switched to Flutter 🐦 and all my react native problems are solved 🤡