[英]PanResponder & Animated Problem in React Native
im using PanResponder in React Native but i have a simple problem that i can't solve!!!我在 React Native 中使用 PanResponder 但我有一个简单的问题我无法解决!!!
this is my code这是我的代码
class test extends React.Component {
constructor(props) {
super(props);
const position = new Animated.ValueXY();
const panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: (evt, gs) => {
console.log(gs.dx);
position.setValue({ x: gs.dx , y: gs.dy })
},
onPanResponderRelease: (evt, gs) => {
},
});
this.state = { panResponder, position }
}
getCardStyle() {
const { position } = this.state;
return {
...position.getLayout(),
};
}
render() {
return (
<View>
{
this.props.cart.map((item, index) => {
return (
<Animated.View style={[this.getCardStyle() ,styles.CardContainer]} key={item.id}
{...this.state.panResponder.panHandlers}
>
<View><Image style={styles.image} source={{ uri: item.src}} /></View>
<Text style={styles.title}>{item.location}</Text>
</Animated.View>
)
})
}
</View>
);
}
}
i want to move every item finger Separately but when i touch every item in list whole items start moving.我想分别移动每个项目手指但是当我触摸列表中的每个项目时,整个项目开始移动。
can anyone help me please??谁能帮帮我??
SOLVE IT解决这个问题
I made another component named ListItem and in that component render FlatList items and it worked!我制作了另一个名为 ListItem 的组件,并在该组件中渲染了 FlatList 项目,它起作用了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.