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

[v4] | [v2] BottomSheetModal Not Closing onPress outside / cant slide the bottomsheet , touches working only inside bottomsheet

Open yunesuk opened this issue 4 years ago • 4 comments

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>

yunesuk avatar Apr 22 '22 14:04 yunesuk

Did you solve this? Having the same issue.

klincoder avatar Nov 23 '22 20:11 klincoder

@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.

dIvYaNshhh avatar Aug 08 '24 05:08 dIvYaNshhh

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)',
  },
})

dIvYaNshhh avatar Aug 08 '24 06:08 dIvYaNshhh

i have switched to Flutter 🐦 and all my react native problems are solved 🤡

yunesuk avatar Aug 08 '24 07:08 yunesuk