美文网首页
React Native 页面实现通知监听事件

React Native 页面实现通知监听事件

作者: TaoGeNet | 来源:发表于2016-12-13 17:31 被阅读2838次

1. 只在React Native页面里发送和接受消息

A页面:

import {DeviceEventEmitter} from 'react-native'

componentDidMount(){

     this.subscription = DeviceEventEmitter.addListener('noticeName', Function);

}

componentWillUnmount(){

this.subscription.remove();

}

B页面:

import {DeviceEventEmitter} from 'react-native';

//post通知信息

DeviceEventEmitter.emit('noticeName', param);

2. 在ReactNative 项目中实现通知事件监听,在Native中实现转发机制

相关文章

网友评论

      本文标题:React Native 页面实现通知监听事件

      本文链接:https://www.haomeiwen.com/subject/pdmduttx.html