我创建了一个显示模态的组件,如下所示:
export default class Modal extends React.Component {
constructor(props) {
super(props);
this.state = {
animationType: 'slide',
modalVisible: true,
props: null,
color: '#282727'
}
}
hideModal = () => {
this.setState({
modalVisible: false,
})
}
render() {
return (
<View>
<Modal
animationType={this.state.animationType}
transparent={true}
visible={this.state.modalVisible}
onRequestClose={() => this.hideModal}
onOrientationChange={evt => this.setState({ currentOrientation: evt.nativeEvent.orientation })}
>
<Container>
<Content style={styles.container}>
<Card style={styles.card}>
<Text></Text>
</Card>
</Content>
</Container >
</Modal >
</View >
);
}
}
我正在使用以下组件调用模式:
import customModal from '../customModal';
export default class CardsList extends Component {
constructor(props) {
super(props);
this.state = {
Modal: null,
}
}
showModal = () => {
let Modal = <customModal />;
this.setState({ Modal })
}
hideModal = () => {
this.setState({
Modal: null
})
render() {
return (
<Container style={{ backgroundColor: '#f7f7f7' }}>
<Content>
{this.state.Modal}
</Content>
<Button onPress={this.showMenu}>
Show Modal
</Button>
</Container>
);
}
}
我正面临以下问题: