- React Native Blueprints
- Emilio Rodriguez Martinez
- 268字
- 2021-07-02 15:20:03
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.
- Linux實(shí)戰(zhàn)
- Ganglia系統(tǒng)監(jiān)控
- Mastering KVM Virtualization
- 奔跑吧 Linux內(nèi)核(入門篇)
- Java EE 8 Design Patterns and Best Practices
- Linux使用和管理指南:從云原生到可觀測(cè)性
- Dreamweaver CS5.5 Mobile and Web Development with HTML5,CSS3,and jQuery
- Mastering Reactive JavaScript
- Django Project Blueprints
- Distributed Computing with Go
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程(Windows 7+MS Office 2010)
- Learning IBM Watson Analytics
- Docker容器技術(shù)與運(yùn)維
- 每天5分鐘玩轉(zhuǎn)Docker容器技術(shù)
- Serverless Architectures with Kubernetes