React-native-gesture-handler: Listener available for PanGestureHandler?

Created on 3 Jan 2018  路  2Comments  路  Source: software-mansion/react-native-gesture-handler

Is it possible to get the value of a PanGestureHandler x/y? I鈥檓 working on a Slider component and I need the value as it鈥檚 being dragged.

Most helpful comment

This IS possible! It鈥檚 just an Animated.event() which accepts an object as the second arg which contains an async listener. If anyone is interested and not sure what I mean it looks like:

this._onGestureEvent = Animated.event(
  [
    {
      nativeEvent: {
        translationX: this._translateX,
      },
    },
  ],
  {
    useNativeDriver: true,
    listener: e => {
      this.setState({ x: Math.floor(e.nativeEvent.translationX) });
    },
  },
);

All 2 comments

This IS possible! It鈥檚 just an Animated.event() which accepts an object as the second arg which contains an async listener. If anyone is interested and not sure what I mean it looks like:

this._onGestureEvent = Animated.event(
  [
    {
      nativeEvent: {
        translationX: this._translateX,
      },
    },
  ],
  {
    useNativeDriver: true,
    listener: e => {
      this.setState({ x: Math.floor(e.nativeEvent.translationX) });
    },
  },
);

@zachgibson you can also do sth like:

this._translateX.addListener(value => console.log("VALUE", value))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

radex picture radex  路  3Comments

TerrerSandman picture TerrerSandman  路  3Comments

alexthebake picture alexthebake  路  3Comments

rgangopadhya picture rgangopadhya  路  4Comments

rt2zz picture rt2zz  路  4Comments