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.

Inconsistent behavior of onGestureEvent

See original GitHub issue

Hi, thanks for this nice library.

I have the following code:

this.translateX = new Animated.Value(0);

this.onGestureEvent = Animated.event(
    [{ nativeEvent: { translationX: this.translateX } }],
    { useNativeDriver: true },
);

this.translateX.addListener(({ value }) => console.log(value));

<PanGestureHandler onGestureEvent={this.onGestureEvent}>...</PanGestureHandler>

On iOS, after loading the application, the console will be empty (the listener not triggered, as expected). On Android, we’ll see the initial value of Animated.Value (0 in this case, i.e. the listener triggered off).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
kmagieracommented, Nov 19, 2018

@luutruong in your case I bet that the reason was that the inner child of GestureHandler component was not an Animated.View. When you want to use Animated.event for event handlers you need to make sure that the child of the gesture-handler component is Animated.View (or Animated.Image etc) as opposed to it just being a View or sth

0reactions
jkadamczykcommented, Oct 13, 2020

I tried the repro @jakub-gonet provided and with some help of @kmagiera I was able to reproduce the exact same issue with Animated.ScrollView the issue is not coming from the Gesture Handler but React Native Animated library.

Because of that I’m closing the issue.

Below example that I used to repro that 😄

// https://github.com/software-mansion/react-native-gesture-handler/issues/263

import React from 'react';
import { SafeAreaView, Animated, Platform, ScrollView } from 'react-native';

const transX = new Animated.Value(0);
const onScroll = Animated.event(
  [{ nativeEvent: { translationX: transX } }],
  { useNativeDriver: true } // only shows if `useNativeDriver: true` 
);
transX.addListener(({ value }) =>
  console.log(`onGestureEvent, ${Platform.OS}, value: ${value}`)
);

export default () => {
  return (
    <SafeAreaView style={[{ flex: 1 }, styles.container]}>
      <Animated.ScrollView onScroll={onScroll}>
        <Animated.View
          style={[
            styles.rectangle,
            styles.container,
            {
              /* not necessary, but you can wiggle the View if present :> */
              transform: [{ translateX: transX }],
            },
          ]}
        />
      </Animated.ScrollView>
    </SafeAreaView>
  );
};

const styles = {
  container: { justifyContent: 'center', alignItems: 'center' },
  rectangle: {
    backgroundColor: 'pink',
    width: 100,
    height: 100,
  },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Does onGestureEvent of TapGestureHandler never fire?
Keep in mind that onGestureEvent is only generated in continuous gesture handlers and shouldn't be used in the TapGestureHandler and other ...
Read more >
content/public/test/browser_test_utils.cc - chromium/src
RegisterThrottleForTesting has this behavior. class TestNavigationManagerThrottle : public NavigationThrottle {. public: ... get into an inconsistent state.
Read more >
react-native-gesture-handler - Bountysource
Hi ! I have a little issue on Android, onGestureEvent is not trigger when GestureHandler components is on a modal on Android. When...
Read more >
browser_view.cc - Chromium Code Search
Widget::IsActive is inconsistent between Mac and Aura, so don't check for ... Manually clear focus before setting focus behavior so that the focus....
Read more >
react-native-gesture-handler: Versions - Openbase
Adjust Swipeable's overshootFriction behavior (#1275) by @kolking ... [WEB] Fix x/y for PanGestureHandler onGestureEvent by @awinograd (#799) ...
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