zoukankan      html  css  js  c++  java
  • React Native 中 跨页面间通信解决方案之 react-native-event-bus

    https://github.com/crazycodeboy/react-native-event-bus

    用法: A页面和B页面中都有相同的列表,点击B页面中的收藏按钮,A页面会跟着更新

    import EventBus from 'react-native-event-bus';
    constructor(props){
        super(props);
        const {tabLabel} = this.props;
        this.storeName = tabLabel;
        this.isFavoriteChanged = false;
      }
    
      componentDidMount(){
        this.loadData();
        EventBus.getInstance().addListener(EventTypes.favorite_changed_popular,this.favoriteChangeListener = ()=>{
          this.isFavoriteChanged = true;
        });
        EventBus.getInstance().addListener(EventTypes.bottom_tab_select,this.bottomTabSelectListener = (data)=>{
          if(data.to === 0 && this.isFavoriteChanged){
            this.loadData(null,true);
          }
        });
      }
    
      componentWillUnmount(){
        EventBus.getInstance().removeListener(this.favoriteChangeListener);
        EventBus.getInstance().removeListener(this.bottomTabSelectListener);
      }
    onFavorite(item,isFavorite){
        
        FavoriteUtil.onFavorite(this.favoriteDao,item,isFavorite,this.props.flag);
        if(this.storeName === FLAG_STORAGE.flag_popular){
          EventBus.getInstance().fireEvent(EventTypes.favorite_changed_popular);
        }
        else{
          EventBus.getInstance().fireEvent(EventTypes.favorite_changed_trending );
        }
      }
    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    python的logging模块
    python的random模块
    python3中time模块的用法及说明
    浅谈python模块的导入操作
    python3中,os.path模块下常用的用法总结
    OS模块的常用内置方法
    认识python中的set集合及其用法
    初识Python装饰器
    CentOS的软件包的管理之rpm和yum
    python中的函数对象与闭包函数
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/11653607.html
Copyright © 2011-2022 走看看