React Native Gesture Handler显示:undefined不是对象

时间:2019-11-27 05:01:40

标签: react-native react-native-gesture-handler

我已经设置了一个本机反应0.61项目,该项目运行时没有任何错误,但是每当我滑动时都会得到它。我正在使用 react-native-gesture-handler:1.3.0

我的

  

TypeError:未定义不是对象(正在评估'rectEvt [mappingKey]')。有关详细信息,请参见image

我正在使用以下代码:

const circleRadius = 30;
class Circle extends Component {
  _touchX = new Animated.Value(windowWidth / 2 - circleRadius);
  _onPanGestureEvent = Animated.event([{nativeEvent: {x: this._touchX}}, { useNativeDriver: true }]);
  render() {
    return (
      <PanGestureHandler
        onGestureEvent={this._onPanGestureEvent}>
        <Animated.View style={{
          height: 150,
          justifyContent: 'center',
        }}>
          <Animated.View
            style={[{
                backgroundColor: '#42a5f5', borderRadius: circleRadius, height: circleRadius * 2, width: circleRadius * 2,
              }, {
                transform: [{translateX: Animated.add(this._touchX, new Animated.Value(-circleRadius))}]
              }]}
          />
        </Animated.View>
      </PanGestureHandler>
    );
  }
}

1 个答案:

答案 0 :(得分:1)

您将错误地将参数传递给 Animated.event

_onPanGestureEvent = Animated.event([{nativeEvent: {x: this._touchX}}, { useNativeDriver: true }]);

Animated.event应该具有以下结构:

_onPanGestureEvent=Animated.event(
   [{nativeEvent: {x: this._touchX}}],
   { useNativeDriver: true }
   {listener},          // Optional async listener
 )