事件的订阅与发送:DeviceEventEmitter
注册事件监听
import {
DeviceEventEmitter,} from 'react-native';
class XiFan extends Component {
componentDidMount(){
this.subscription = DeviceEventEmitter.addListener('dataChange',this._onListenerCallback.bind(this));
}
componentWillUnmount(){
this.subscription.remove();
}
_onListenerCallback(params){
console.log('params = '+ params);
};
}
DeviceEventEmitter.emit('dataChange',params);
原文链接:https://www.f2er.com/react/306226.html