1

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

我的

类型错误:未定义不是对象(评估“rectEvt [mappingKey]”)。详情请看图片

我正在使用以下代码:

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>
    );
  }
}
4

1 回答 1

0

您以错误的方式将参数传递给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
 )
于 2019-11-27T05:12:11.707 回答