这些是我的依赖项:
"dependencies": {
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-native-easy-grid": "^0.2.0",
"react-native-elements": "^1.0.0-beta5"
}
这是我的代码:
constructor(props){
super(props)
this.state = {pan: new Animated.ValueXY({x:0 , y:0})}
this._PanResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onStartShouldSetPanResponder: (event, gesture) => true,
onPanResponderMove: (event, gesture) => {
this.state.pan.setValue({x:gesture.dx , y:gesture.dy})
},
onPanResponderRelease: (e, {dx, dy}) => {
console.log(dx, dy);
this.state.pan.setValue({x:dx , y:dy})
}
})
}
它已连接到:
<Animated.View key={item.id} style={this.state.pan.getLayout()} {...this._PanResponder.panHandlers}>
{this.props.renderCard(item)}
</Animated.View>
当我重新单击图像时,该位置会重置到屏幕顶部(这也不是卡的默认点)。 我希望图像能够在再次被触摸后保持其位置。