React-native-router-flux 场景多次渲染 [英] React-native-router-flux scene render multiple times
本文介绍了React-native-router-flux 场景多次渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我使用 react-native-router-flux,这是我的场景
So I use react-native-router-flux and here is my scene
<Scene key="changePassword" component={ChangePassword} title="Change Password"/>
我有这个按钮,点击后会路由到那个场景
And I have this button which will route to that scene when clicked
<Button style={styles.button} onPress={() => Actions.changePassword()}>
如果我多次点击按钮,会弹出多个场景.
有什么办法可以防止这种情况发生吗?谢谢你们的帮助 :)
Is there any way to prevent this? Thank you for your help guys :)
推荐答案
如果按钮被点击,你可以尝试给予延迟,像这样放置本地状态:
you can try to give delay if the button has been clicked, put local state like this:
constructor() {
super()
this.state = {
inClick: false
}
}
并添加此功能:
onClickButton = () => {
this.setState({ inClick: true })
Actions.register()
setTimeout(function() { this.setState({inClick: false}); }.bind(this), 2000);
}
在你的按钮中应该是这样的:
and in your button should be like this :
<Button warning block style={styles.button} onPress={ !this.state.inClick ? this.onClickButton : null}>
希望能帮到你,谢谢:)
Hope that can help you, thanks :)
这篇关于React-native-router-flux 场景多次渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文