React native android modal visible设置为false但仍然显示

时间:2016-08-31 05:02:25

标签: react-native

我已将模态可见性设置为false但仍显示。我无法弄清楚导致这个问题的原因。也许以前有人遇到过这个问题?

 export default class Controls extends Component {
  constructor(props) {
    super();

    this.state = {
      modalVisible: false,
    }
}

 render() {
   return (
     <Modal
       animationType={'slide'}
       modalVisible={this.state.modalVisible}
       >
     </Modal>
   );
  }
}

1 个答案:

答案 0 :(得分:1)

控制模态可见性的道具为visible而不是modalVisible

因此正确的代码是:

&#13;
&#13;
export default class Controls extends Component {
  constructor(props) {
    super();

    this.state = {
      modalVisible: false,
    }
}

 render() {
   return (
     <Modal
       animationType={'slide'}
       visible={this.state.modalVisible}
       >
     </Modal>
   );
  }
}
&#13;
&#13;
&#13;