【问题标题】:React-native-router-flux scene render multiple timesReact-native-router-flux 场景渲染多次
【发布时间】:2018-01-18 20:59:20
【问题描述】:

所以我使用 react-native-router-flux,这是我的场景

<Scene key="changePassword" component={ChangePassword} title="Change Password"/>

我有这个按钮,点击后会跳转到那个场景

<Button style={styles.button} onPress={() => Actions.changePassword()}>

如果我多次点击按钮,会弹出多个场景。

有什么办法可以防止这种情况发生吗?谢谢你们的帮助:)

【问题讨论】:

    标签: javascript react-native react-native-router-flux


    【解决方案1】:

    如果按钮被点击,你可以尝试延迟,像这样放置本地状态:

    constructor() {
        super()
        this.state = {
          inClick: false
        }
      }
    

    并添加此功能:

    onClickButton = () => {
        this.setState({ inClick: true })
        Actions.register()
        setTimeout(function() { this.setState({inClick: false}); }.bind(this), 2000);
      }
    

    你的按钮应该是这样的:

    <Button warning block style={styles.button} onPress={ !this.state.inClick ? this.onClickButton : null}>
    

    希望对你有帮助,谢谢:)

    【讨论】:

      【解决方案2】:

      我认为唯一的方法是禁用按钮,如果它已被点击,反应原生按钮中有一个名为 disabled 的道具。

      function handleButtonClick(){
        this.setState({ disabled: true });
        Actions.changePassword();
      }
      
      
      <Button onPress={()=> this.handleButtonClick()} disabled={this.state.disabled} />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-19
        • 1970-01-01
        • 2017-12-23
        • 2017-01-05
        • 2017-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多