官术网_书友最值得收藏!

Creating our app's entry point

All React Native apps have one entry file: index.js,  we will delegate the root of the component's tree to our src/main.js file:

/*** index.js ***/

import { AppRegistry } from 'react-native';
import App from './src/main';
AppRegistry.registerComponent('rssReader', () => App);

We will also register our app with the operating system.

Now, let's take a look at the src/main.js file to understand how we will set up navigation and start up our component's tree:

/** * src/main.js ***/

import React from 'react';
import { StackNavigator } from 'react-navigation';

import FeedsList from './screens/FeedsList.js';
import FeedDetail from './screens/FeedDetail.js';
import EntryDetail from './screens/EntryDetail.js';
import AddFeed from './screens/AddFeed.js';

import store from './store';

const Navigator = StackNavigator({
FeedsList: { screen: FeedsList },
FeedDetail: { screen: FeedDetail },
EntryDetail: { screen: EntryDetail },
AddFeed: { screen: AddFeed },
});

export default class App extends React.Component {
constructor() {
super();
}

render() {
return <Navigator screenProps={{ store }} />;
}
}

We will use react-navigation as our navigator library and StackNavigator as our navigation pattern. Add each of our screens to the StackNavigator function to generate our <Navigator>. All this is very similar to the navigation pattern we used in Chapter 1, Shopping List, but we incorporated an improvement to it: we are passing store in the screenProps property for our <Navigator>, instead of directly passing the attributes and methods to modify our app's state. This simplifies and cleans up the code base and as we will see in later sections, it will free us from notifying the navigation every time our state changes. All these improvements come for free thanks to MobX.

主站蜘蛛池模板: 蓬安县| 西藏| 连城县| 望奎县| 柞水县| 公主岭市| 元朗区| 夏津县| 宜城市| 黄浦区| 闽侯县| 建水县| 黄大仙区| 萨嘎县| 渭源县| 清丰县| 永平县| 西贡区| 阿拉尔市| 平遥县| 林甸县| 高州市| 山阳县| 府谷县| 长岭县| 宜兰市| 隆林| 万山特区| 山东| 荆门市| 石门县| 宁乡县| 墨竹工卡县| 海伦市| 石嘴山市| 小金县| 陆川县| 南城县| 六盘水市| 勃利县| 正阳县|