Viewpager 中的可触摸突出显示将页面更改事件作为在 react-native ios 中的单击



我们在应用程序中使用了view pager(react-native-community/react-native-viewpager(,每个页面都有3个部分,所有3个部分都是可点击的,为了使其可点击,我们使用TouchableHighlight

因此,每当我通过滑动更改页面时。如果我的滑动触摸在IOSTouchableHighlight内部,它会将其作为单击其他内容,android它工作正常。

发布此内容以获得像我这样的其他用户的帮助。

来自该库开发人员的回答。

嘿 您可以使用 onPageScrollStateChanged 方法,来阻止按钮交互。

switch(pageScrollState){
case "idle": enableButton();
default: disableButton(); 
}

或者我使用了这种方法。

this.state = {
shouldEnableClick: true,
};
pageScroll = (event) => {
draggingValue = event.nativeEvent.offset
isNotStill = (draggingValue == 0 || draggingValue == 1) ? true : false
{Platform.OS == 'ios' && this.changeValue(isNotStill)}
}
changeValue(isNotStill) {
if (this.state.shouldEnableClick !== isNotStill) {
this.setState({ shouldEnableClick: isNotStill })
}
}

在组件中,我像这样使用它

let enableCLick = this.state.shouldEnableClick
let clickAction = () => this.myAction()
<TouchableHighlight
onPress={enableCLick && clickAction}/>

最新更新