代码之家  ›  专栏  ›  技术社区  ›  Hana Alaydrus

反应本机路由器流量场景渲染多次

  •  1
  • Hana Alaydrus  · 技术社区  · 7 年前

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

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

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

    有什么方法可以防止这种情况吗?谢谢你们的帮助,伙计们:)

    2 回复  |  直到 7 年前
        1
  •  1
  •   Rizal Sidik    7 年前

    如果已单击按钮,您可以尝试给予延迟,将本地状态设置为:

    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
  •  1
  •   Ahmed Ali    7 年前

    我认为唯一的方法是禁用按钮,如果它已被单击,则在react native button中有一个名为disabled的道具。

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