仅当手指移动超过屏幕的20%时才进行滚动



我有一个滚动视图,其中包含子项列表(Webview-垂直滚动(。当我尝试垂直滚动Webview时,在父-水平方向上会发生偏转或小的移动。我试着将孩子们的信息传递给家长,以禁用或启用滚动,这是为了放慢速度,而不是100%完美。有没有任何方法可以通过android的react原生滚动视图中的道具来实现这一点。

谢谢你。

我使用react native的PanResponder找到了查询的答案。

componentWillMount() {
this._panResponder = PanResponder.create({
onMoveShouldSetPanResponder: (evt, gestureState) => {
return Math.abs(gestureState.dx) > minDragWidth;
},
onPanResponderMove: (evt, gestureState) => {
if(!this._swipeDirection) this.checkSwipeDirection(gestureState);
},
onPanResponderRelease: (evt, gestureState) => {
this._swipeDirection = null;
},
});
}

因此,当触摸事件启动时和拖动继续时,将分别调用这些函数。

通过检查滚动是水平还是垂直,我们可以执行操作。

checkSwipeDirection(gestureState) {
const isHorizontalSwipe = (Math.abs(gestureState.dx) > Math.abs(gestureState.dy * 3)) && 
(Math.abs(gestureState.vx) > Math.abs(gestureState.vy * 3));
if(isHorizontalSwipe) {
this._swipeDirection = "horizontal";
let index = (gestureState.dx > 0) ? this.state.paginationIndex - 1 : 
this.state.paginationIndex + 1;
index = (index > 0) ? (index > (this.props.data.length - 1) ? (index - 1) : index) : 0;
this._scrollToIndex(index, true);
this.props.doRequiredAction({ index });
} else {
this._swipeDirection = "vertical";
}
}

通过引用此帖子。

最新更新