【发布时间】:2019-06-26 11:38:17
【问题描述】:
我目前遇到了一个问题,我可以很好地打开我的 react-native 模式,但是一旦打开,我似乎无法关闭它。我大约三周前才开始使用 react-native,所以我对此非常陌生。
我已尝试实施我在网上找到的解决方案,但似乎没有什么对我有用。打开功能很棒,似乎工作得很好,但是当谈到关闭模态时,我尝试过的所有事情似乎都没有赋予模态这种能力。我无法在任何地方为我的确切问题找到可靠的解决方案!
这就是我打开模式的方式。
constructor(props) {
super(props);
this.state = {
refreshing: false,
display: false
};
}
triggerModal() {
this.setState(prevState => {
return {
display: true
}
});
}
<View>
<Button onPress = { () => this.triggerModal() } title = "Open Modal"></Button>
<DisplayModal display = { this.state.display } />
</View>
这是模态本身,我正在尝试使用一个按钮来关闭它。
import React from 'react'
import { Modal, View, Image, Text, StyleSheet, Button } from 'react-native';
const DisplayModal = (props) => (
<Modal visible={ props.display } animationType = "slide"
onRequestClose={ this.display }>
<View>
<Button title="close" onPress = { () => !props.display }></Button>
</View>
</Modal>
)
export default DisplayModal;
由于我对 react-native 的了解有限,我很难理解框架的某些方面是如何运作的……我可能只是在代码的某个地方犯了一个愚蠢的错误。
感谢您对这个问题的任何帮助!
【问题讨论】:
标签: javascript react-native expo