【问题标题】:How can I set modalView in false?如何将 modalView 设置为 false?
【发布时间】:2019-08-21 16:23:23
【问题描述】:

我希望在点击 touchableopacity 时,我的应用将模态状态更改为 false

constructor(props) {
    super(props);
    this.state = {
        modalVisible: true,
        first: true,
    }
}
checkIfFirstLog = () => {
    this.setState = {first: false}

    if (this.state.first = false) {
        this.setState = {
            modalVisible: false
        }
    }
}
<Modal           
      <TouchableOpacity onPress={() => this.checkIfFirstLog() }>

      </TouchableOpacity>   
 </Modal>

【问题讨论】:

    标签: function react-native if-statement mobile modalviewcontroller


    【解决方案1】:

    据我了解,您可以使用以下代码:

    constructor(props) {
        super(props);
        this.state = {
            modalVisible: true,
            first: true,
        }
    }
    const checkIfFirstLog = () => {
        this.setState({
            modalVisible: true,
            first: true,
        });
    }
    <Modal           
        <TouchableOpacity onPress={this.checkIfFirstLog}>
    
        </TouchableOpacity>   
    </Modal>
    

    我合并了您在 checkIfFirstLog 方法中使用的两个 setState 操作,因为您已经尝试更改两个状态值。我认为这样会很好。

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多