美文网首页
react-native 通过DeviceEventEmitte

react-native 通过DeviceEventEmitte

作者: jacklin1992 | 来源:发表于2017-06-23 17:37 被阅读47次

场景 页面1 点击按钮进入拍照页面2,页面2拍照并选取照片后需要带着数据跳转回页面1

做法

  1. 页面1中写好事件监听

    componentWillUnmount() {
        this.subscription.remove();
    }
    componentDidMount(){
        this.subscription = DeviceEventEmitter.addListener('refreshPnotos',this.refreshPnotos)
    }
    refreshPnotos(data){
        alert(JSON.stringify(data));
    }
    
  2. 页面2中 在需要的时候调用

     this.picConfirm = function(){
             DeviceEventEmitter.emit('refreshPnotos',_this.state.imageUri);
             navigator.pop();
     };

相关文章

网友评论

      本文标题:react-native 通过DeviceEventEmitte

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