翻译|React-navigation导航系统(4)-Redux的整合实例


title: 翻译|React-navigation导航系统(6)-Redux的整合实例
date: 2017-03-29 23:42:14
categories: 翻译
tags: React-Native


整合实例,其实这完全是Redux的使用,文档里的例子没有写全所以不太好看,github的例子,代码就比较全了.

对Redux的概念理解了这个看起来就简单一点.如果对于Redux的概念不理解,可以看我的几篇翻译文章和前面写的Redux的理解文章.
没有目录导航,不是太好看.可以看看我的博客,里面有目录结构.
我理解其中的流程就是,

  1. React组件接受props,获取state和dispatch.
  2. 组件dispatch action改变navigation的state.
    3.根据state的相应变化加载对应的screen.
/**
 * @flow
 */

import React from 'react';
import {
  AppRegistry,
  AsyncStorage,
  Button,
  StyleSheet,
  Text,
  View,
} from 'react-native';
import {
  NavigationActions,
  addNavigationHelpers,
  StackNavigator,
} from 'react-navigation';
import {
  Provider,
  connect,//redux,connect函数,负责向展示组件注入state和dispatch
} from 'react-redux';
import {
  createStore,
  combineReducers,
} from 'redux';
import {
  persistStore,
  autoRehydrate,
} from 'redux-persist';//redux state持久化的中间件

const ProfileScreen = ({ navigation }) => (//这个组件没有dispatch
  
    
      Profile Screen
    
  
);
ProfileScreen.navigationOptions = {//配置navigationOptions对象
  title: 'Profile',
};

const LoginScreen = ({ navigation }) => (
  
    
      Screen A
    
    
      This is great
    
    

你可能感兴趣的:(翻译|React-navigation导航系统(4)-Redux的整合实例)