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.

Receiving simultaneous ScrollView and GestureHandler events

See original GitHub issue

Is it possible to receive events for a handler, e.g. PanGestureHandler, and a ScrollView at the same time? I’m finding that a ScrollView fully consumes a touch event, even with simultaneousHandlers set, so that a gesture handler that contains the ScrollView never receives the touch as long as the ScrollView is enabled.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

21reactions
damikdkcommented, Nov 20, 2019

There is no documentation about NativeViewGestureHandler on official site, but the only mention of it says that you can use FlatList from react-native-gesture-handler with simultaneousHandlers instead of wrapping it inside NativeViewGestureHandler.

But you cannot

import { FlatList, PanGestureHandler } from 'react-native-gesture-handler';

// This handler will only fire if FlatList does not detect scroll
<PanGestureHandler
  ref={panRef}
  simultaneousHandlers={listRef}
>
  <FlatList
    ref={listRef}
    simultaneousHandlers={panRef}
    ...
  />
</PanGestureHandler>

So you still should use FlatListONLY from react-native and wrap it in NativeViewGestureHandler:

import { FlatList } from 'react-native';
import { PanGestureHandler, NativeViewGestureHandler } from 'react-native-gesture-handler';

<PanGestureHandler
  ref={panRef}
  simultaneousHandlers={listRef}
>
  <NativeViewGestureHandler
    ref={listRef}
    simultaneousHandlers={panRef}
  />
    <FlatList/>
  </NativeViewGestureHandler>
</PanGestureHandler>

There is no FlatList in current documentation from this repo. But it was added in this PR. IDK

5reactions
yzalvovcommented, Mar 27, 2020

@damikdk thanks, your research helped me.

I’d add one caveat though. For anybody planning to use an Animated.event for a PanGestureHandler onHandlerStateChange for example. In that case one must wrap a NativeViewGestureHandler inside an Animated.View. Otherwise the app will be failing with an error Nesting touch handlers with native animated driver is not supported yet.

Credits: #71

Just in case, here’s a full example:

const ScrollContainer = styled(Animated.ScrollView).attrs({
  scrollEventThrottle: 16,
  contentContainerStyle: { paddingBottom: 40 },
})``


const Container = React.forwardRef((props, ref) => {
  const handlerRef = useRef()
  const { onScroll, onHandlerStateChange, children } = props
  
return <PanGestureHandler {...{onHandlerStateChange}} simultaneousHandlers={handlerRef}>

    <Animated.View>

      <NativeViewGestureHandler ref={handlerRef}>
        <ScrollContainer ref={ref} {...{onScroll}}>
          {children}
        </ScrollContainer>
      </NativeViewGestureHandler>

    </Animated.View>

  </PanGestureHandler>
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross handler interactions | React Native Gesture Handler
Gesture handlers can "communicate" with each other to support complex gestures and control how they activate in certain scenarios.
Read more >
How can I use react-native-gesture-handler to handle react ...
To reiterate, what I wanted to do was to have the touch events of a ScrollView work simultaneously with touch events from a ......
Read more >
Gesture Responder System - React Native
There can also be multiple simultaneous touches. ... target - The node id of the element receiving the touch event; timestamp - A...
Read more >
ScrollView from scratch with PanGestureHandler in ... - YouTube
In this tutorial we'll learn how to recreate the scroll behavior with just a PanGestureHandler component (from react-native- gesture-handler ...
Read more >
DragGesture in SwiftUI ScrollView … | Apple Developer Forums
The gesture's events properly fire when you drag vertically, but when you drag horizontally (matching the direction of the scroll view) only the...
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