gpt4 book ai didi

ios - Viewpager 内的 TouchableHighlight 将页面更改事件作​​为 react native ios 中的单击

转载 作者:行者123 更新时间:2023-11-29 05:15:43 24 4
gpt4 key购买 nike

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

所以每当我通过滑动更改页面时。如果我的滑动触摸位于 IOS 中的 TouchableHighlight 内部,它会将其视为 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}/>

关于ios - Viewpager 内的 TouchableHighlight 将页面更改事件作​​为 react native ios 中的单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59211543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com