React Native的模态,AsyncStorage,DeviceEventEmitter

xiaoxiao2021-02-27  168

1.模态modal

A界面

<Modal animationType='slide' transparent={false} visible={this.state.isModal} onRequestClose={() => this.onRequestClose()}> <HalfHourHot removeModal={(data) => this.closeModal(data)}/> </Modal> constructor(props) { super(props); this.state = { isModal: false, }; }; onRequestClose() { this.setState({ isModal: false, }); }; closeModal(data) { this.setState({ isModal: data, }); };

HalfHourHot界面必须有一个removeModal属性,且是func

static propTypes = { removeModal: PropTypes.func, }; //某处操作需要返回到A界面 popToHome(data) { //this.props.navigator.pop(); this.props.removeModal(data); }

2.AsyncStorage—SharedPreferences

http://www.cnblogs.com/huangjialin/p/6245122.html

3.DeviceEventEmitter—发送通知

A界面

componentDidMount() { this.listener = DeviceEventEmitter.addListener('listen', (value) => { console.log(value.num); }); }; componentWillUnmount() { this.listener.remove('listen'); };

B界面发送

DeviceEventEmitter.emit('listen', {num: 12});
转载请注明原文地址: https://www.6miu.com/read-14619.html

最新回复(0)