很简单,直接代码,一看就懂
import React from'react';
import {Text, View, TouchableOpacity, Modal} from 'react-native';
export default class ConferenceCallPage extends React.PureComponent {
show() {
this.setState({isPop: true });
}
state = { isPop: false };
render() {
return (
<Modal animationType="slide" visible={this.state.isPop}>
<View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
<Text style={{color:'red',fontSize:18,width:300}}>我是modal出来的视图</Text>
<Text onPress={()=>this.setState({isPop:false})} style={{color:'red',fontSize:18, marginTop:100}}>点我取消</Text>
</View>
</Modal>
);
}
}
如下使用:
在想要弹出视图的组件render方法中写上下面
<ConferenceCallPage ref="conferenceCallPage"/>
点击按钮调用方法
this.refs.conferenceCallPage.show()