簡體   English   中英

react-native-router-flux場景渲染多次

[英]React-native-router-flux scene render multiple times

所以我用react-native-router-flux這是我的場景

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

我有這個按鈕,當單擊該按鈕時,它將轉到該場景

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

如果我多次單擊該按鈕,將彈出多個場景。

有什么辦法可以防止這種情況? 謝謝您的幫助:)

我認為唯一的方法是禁用已單擊的按鈕,在react native按鈕中有一個名為Disabled的道具。

function handleButtonClick(){
  this.setState({ disabled: true });
  Actions.changePassword();
}


<Button onPress={()=> this.handleButtonClick()} disabled={this.state.disabled} />

如果單擊按鈕,則可以嘗試延遲,將本地狀態設置為:

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}>

希望能對您有所幫助,謝謝:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM