zoukankan      html  css  js  c++  java
  • react-native--->RN发送/接收事件机制

    import {
        AppRegistry,
        StyleSheet,
        Text,
        View,
        Platform,
        NativeAppEventEmitter,
        DeviceEventEmitter,
    } from 'react-native';
    
    //添加DeviceEventEmitter
    
    componentDidMount() {
    	if(Platform.OS=='android'){
    	    this.subscription = DeviceEventEmitter.addListener('userNameDidChange',(userName) => {
            alert('通知');
        })
    	}else {
    	    this.subscription = NativeAppEventEmitter.addListener('userNameDidChange',(userName) => {
            alert('通知');
        })
    	}
    
    },
    
    移除DeviceEventEmitter
    componentWillUnmount() {
        // 移除
        this.subscription.remove();
    },
    
    发送通知
    DeviceEventEmitter.emit('userNameDidChange', '通知来了');
    
    OK, 完成!
    
  • 相关阅读:
    简易计算机
    作业-继承
    exception
    作业-窗口
    作业-数字
    作业8
    作业9-1
    作业9-2
    book
    成绩录入
  • 原文地址:https://www.cnblogs.com/frankltf/p/7741896.html
Copyright © 2011-2022 走看看