RN-NavigationExperimental-Redux-Example 项目教程
1. 项目的目录结构及介绍
RN-NavigationExperimental-Redux-Example/
├── android/
├── ios/
├── src/
│ ├── actions/
│ ├── components/
│ ├── reducers/
│ ├── store/
│ └── index.js
├── .buckconfig
├── .flowconfig
├── .gitignore
├── .watchmanconfig
├── package.json
└── README.md
android/
和ios/
:包含Android和iOS的原生代码。src/
:项目的源代码目录。actions/
:存放Redux actions。components/
:存放React组件。reducers/
:存放Redux reducers。store/
:存放Redux store配置。index.js
:项目的入口文件。
.buckconfig
,.flowconfig
,.gitignore
,.watchmanconfig
:配置文件。package.json
:项目的依赖和脚本配置。README.md
:项目的说明文档。
2. 项目的启动文件介绍
项目的启动文件是 src/index.js
,它负责初始化React Native应用和Redux store,并将它们连接起来。
import React from 'react';
import { AppRegistry } from 'react-native';
import { Provider } from 'react-redux';
import App from './components/App';
import configureStore from './store/configureStore';
const store = configureStore();
const RNRedux = () => (
<Provider store={store}>
<App />
</Provider>
);
AppRegistry.registerComponent('RNNavigationExperimentalReduxExample', () => RNRedux);
Provider
:将Redux store提供给React组件。App
:应用的根组件。configureStore
:配置Redux store的函数。
3. 项目的配置文件介绍
.buckconfig
Buck构建系统的配置文件。
.flowconfig
Flow类型检查工具的配置文件。
.gitignore
Git版本控制系统的忽略文件配置。
.watchmanconfig
Watchman文件监视工具的配置文件。
package.json
项目的依赖和脚本配置文件。
{
"name": "RN-NavigationExperimental-Redux-Example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios"
},
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-redux": "^5.0.4",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "16.0.0-alpha.6"
},
"jest": {
"preset": "react-native"
}
}
scripts
:定义了启动和运行应用的命令。dependencies
:项目的生产依赖。devDependencies
:项目的开发依赖。jest
:Jest测试框架的配置。