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

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.

主站蜘蛛池模板: 日土县| 霞浦县| 加查县| 卓尼县| 锦屏县| 孝义市| 龙门县| 吉林省| 黄石市| 自贡市| 梧州市| 咸丰县| 石嘴山市| 垣曲县| 孟村| 囊谦县| 顺义区| 盐池县| 贵港市| 平度市| 溆浦县| 长沙市| 长泰县| 鄂尔多斯市| 页游| 江达县| 河西区| 宜宾县| 嘉鱼县| 兴国县| 开鲁县| 拉孜县| 临邑县| 疏勒县| 自贡市| 太原市| 邵阳县| 深州市| 涟水县| 崇信县| 怀宁县|