React Native Gesture Handler 显示:undefined 不是对象
React Native Gesture Handler shows: undefined is not an object
我已经设置了一个 react-native 0.61 项目,它运行时没有任何错误,但是每当我滑动时我都会得到这个。我正在使用 react-native-gesture-handler: 1.3.0.
我的
TypeError: Undefined is not an object (evaluating 'rectEvt[mappingKey]'). Please see the image for detail
我正在使用以下代码:
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>
);
}
}
您以错误的方式将参数传递给 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
)
我已经设置了一个 react-native 0.61 项目,它运行时没有任何错误,但是每当我滑动时我都会得到这个。我正在使用 react-native-gesture-handler: 1.3.0.
我的
TypeError: Undefined is not an object (evaluating 'rectEvt[mappingKey]'). Please see the image for detail
我正在使用以下代码:
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>
);
}
}
您以错误的方式将参数传递给 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
)