【发布时间】:2021-08-06 10:56:27
【问题描述】:
我们都在手机中使用一些图库应用。在图库中尝试删除照片时,我们可以通过滑动手指来选择多张图片。
我不知道this的关键字,我搜索但找不到事件或处理程序。我真的想在我的应用程序上使用它来选择多个组件列表项。
什么是关键字以及如何实现它。有人帮忙吗?
这是我做的
constructor(props) {
super(props);
const panResponder = PanResponder.create({
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderMove: (event, gesture) => {
console.log('do',gesture);
}
});
渲染
{this.state.hours.map((hours, index) => {
return (
<View
style={{
backgroundColor: 'red',
}}
{...this.state.panResponder.panHandlers}>
<TouchableOpacity
style={{backgroundColor: 'blue'}}
onPress={() => {
this.hoursSelect(hours, index);
}}>
<hoursComponent
hoursText={hours.hoursText}
isSelected={hours.isSelected}
hours={hours}
pushSecilihours={this.pushhours}
/>
</TouchableOpacity>
</View>
);
})}
触摸不到的值
这是我需要做的。滑动或触摸组件并获取值。 谢谢。
我可以得到 x y 坐标值但是如何使用它。
【问题讨论】:
-
谁能写点东西
-
如果你问我,我可以提供更多细节
-
思路是通过onLayout方法获取item的偏移量,然后使用PanHandler匹配item layout的值和当前的offset值,如果匹配则标记为选中。
-
最后一部分很容易设置为选中,但其他部分。我添加了一些代码
-
你解决了吗?
标签: react-native uigesturerecognizer uipangesturerecognizer