Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To enable scrolling within the Gesture Detector in React Native, you can wrap the ScrollView component inside the Gesture Detector component.

Here is an example code:

import React, { Component } from 'react';
import { ScrollView, View, Text } from 'react-native';
import GestureRecognizer, { swipeDirections } from 'react-native-swipe-gestures';

class ExampleScreen extends Component {
  onSwipeDown(gestureState) {
    console.log('You swiped down!');
  }

  render() {
    const config = {
      velocityThreshold: 0.3,
      directionalOffsetThreshold: 80
    };

    return (
      <GestureRecognizer
        onSwipeDown={(state) => this.onSwipeDown(state)}
        config={config}>
        <ScrollView>
          <View>
            <Text>Scrollable Content Here</Text>
          </View>
        </ScrollView>
      </GestureRecognizer>
    );
  }
}

In this example, we import the ScrollView and GestureRecognizer from their respective packages. We then define an onSwipeDown function that will be called when the user swipes down on the screen.

Inside the render method, we wrap the ScrollView inside the GestureRecognizer component, passing the onSwipeDown function as a prop. We also pass in a configuration object to adjust the sensitivity of the swipe gesture.

Now, the user can both scroll and swipe on the screen, and the Gesture Detector will properly handle the gesture events.