question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TouchableOpacity from React Native Gesture Handler doesn't work inside Modal

See original GitHub issue

Bug

Using react-native-gesture-handler’s TouchableOpacity inside BottomSheetModal doesn’t work. However, react-native’s Button inside BottomSheetModal does work.

https://user-images.githubusercontent.com/36211796/104091363-e76b6500-52b7-11eb-8a24-579198a35196.MP4

Environment info

Library Version
@gorhom/bottom-sheet ^2.0.2
expo ~40.0.0
react-native https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz
react-native-reanimated 2.0.0-rc.0
react-native-gesture-handler ~1.8.0

Steps To Reproduce

  1. expo init (basic config)
  2. yarn add @gorhom/bottom-sheet react-native-reanimated@2.0.0-rc.0 react-native-gesture-handler
  3. Replace App.js with the code below.

Describe what you expected to happen:

  1. Touchable Opacity inside the modal should register presses

Reproducible sample code

import {
  BottomSheetModal,
  BottomSheetModalProvider
} from '@gorhom/bottom-sheet';
import React, { useCallback, useRef, useState } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { TouchableOpacity } from "react-native-gesture-handler";

const App = () => {
  const [count, setCount] = useState(1)

  const bottomSheetModalRef = useRef(null);

  const handlePresentModalPress = useCallback(() => {
    bottomSheetModalRef.current?.present();
  }, []);

  return (
    <BottomSheetModalProvider>
      <View style={styles.container}>
        <Button
          onPress={handlePresentModalPress}
          title="Present Modal"
          color="black"
        />
        <BottomSheetModal
          ref={bottomSheetModalRef}
          snapPoints={["50%"]}
        >
          <View style={styles.contentContainer}>
            <TouchableOpacity onPress={() => setCount(p => p + 1)}><Text style={{color: "blue", fontSize: 18}}>Increase count with Touchable Opacity</Text></TouchableOpacity>
            <Button title="increase count with RN Button" onPress={() => setCount(p => p + 1)}/>
            <Text>{count}</Text>
          </View>
        </BottomSheetModal>
      </View>
    </BottomSheetModalProvider>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
    justifyContent: 'center',
    backgroundColor: 'grey',
  },
  contentContainer: {
    flex: 1,
    justifyContent: "center",
    alignItems: 'center',
  },
});

export default App;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

TouchableOpacity and button not working in react native Modal?
My problem was that I imported the TouchableOpacity from the react-native-gesture-handler package, rather then the default react-native ...
Read more >
Troubleshooting | React Native Bottom Sheet - GitHub Pages
Pressables / Touchables are not working on Android​. Due to wrapping the content and handle with TapGestureHandler & PanGestureHandler , any gesture interaction ......
Read more >
react-native-modalize - npm
In a future version of react-native , the Modal component will be moved out from the core. Besides, react-native-gesture-handler for Android ...
Read more >
Introduction | React Native Gesture Handler - Software Mansion
The ability to define relations between gesture handlers, e.g. when you have a pan handler in ScrollView you can make that ScrollView wait...
Read more >
Accessibility - React Native
Create mobile apps accessible to assistive technology with React Native's suite of APIs designed to work with Android and iOS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found