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.

PanGestureHandler w/o child Animated?

See original GitHub issue

I have a use case where I need to know about drag events but don’t actually want to animate the direct child of the PanGestureHandler.

For example, the following code for a “Draggable” component does not work:

      <View>
        {/* Note how the Animated.View is outside PanGestureHandler */}
        <Animated.View
          style={[
            {
              transform: [
                { translateX: this._translateX },
                { translateY: this._translateY },
              ],
            },
          ]}
        >
          {/* Clone on drag */}
          {this.state.active && this.props.children}
        </Animated.View>
        
        {/* Listen for drag events */}
        <PanGestureHandler
          onGestureEvent={this._onGestureEvent}
          onHandlerStateChange={this._onHandlerStateChange}>
            {this.props.children}
        </PanGestureHandler>
      </View>

Is this simply not possible?

Issue Analytics

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

github_iconTop GitHub Comments

19reactions
kmagieracommented, Dec 1, 2017

Hey @scottmas sorry for late response on that.

I just tried you example app two comments from now and just made one change in it – replaced View that’s inside PanGestureHandler with Animated.View:

***************
*** 66,70 ****
            onGestureEvent={this._onGestureEvent}
            onHandlerStateChange={this._onHandlerStateChange}>
!           <View style={styles.redBox} />
          </PanGestureHandler>
        </View>
--- 66,70 ----
            onGestureEvent={this._onGestureEvent}
            onHandlerStateChange={this._onHandlerStateChange}>
!           <Animated.View style={styles.redBox} />
          </PanGestureHandler>
        </View>

Panning on the red box makes the other box move now. Not sure if that’s what you’d expect to happen

3reactions
kmagieracommented, Feb 9, 2018

Yes, thanks I think once I have time to finish new docs this information is going to be included

Read more comments on GitHub >

github_iconTop Results From Across the Web

About Gesture Handlers | React Native ... - Software Mansion
Because handlers do not instantiate native views but instead hook up to their child views, directly nesting two gesture handlers using Animated.event is...
Read more >
Pass touch events to child view using react-native-gesture ...
I am using this React-Native-Gesture-Handler for handling my gesture user do on the app. But the gesture seems to not work as expected...
Read more >
How do I properly ad drag-and-drop functionality to ... - Reddit
I'm trying to drag & drop the child elements of a FlatList using react-native-gesture-handler's PanGestureHandler.
Read more >
Building a Draggable Sheet with React Native Reanimated 2
This essentially affords you two screens in one. You may have seen an example when using ... The result is smooth and responsive...
Read more >
Gesture with animation - Expo Snack
import React, { Component } from 'react'; import { StyleSheet, View } from 'react-native'; import { PanGestureHandler, ...
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