RN's first API-----Registration component Appregistry

Source: Internet
Author: User

The first explanation AppRegistry is JS running all react native applications what is the portal?

1. When we initialize a react native project, the default index.ios.js/index.ios.js content is this

(Here we simplify the code)

Import React, {Component} from ' React '; import {  appregistry,  StyleSheet,  Text,  View} from ' React-native '; class Allen extends Component {  render () {    return (      <view style={styles.container}>        <text style={styles.welcome}>          Welcome to React native!        </Text>            </View>    );}  } Const STYLES = stylesheet.create ({  container: {    flex:1,    justifycontent: ' Center ',    alignitems: ' Center ',    backgroundcolor: ' #F5FCFF ',  },}); Appregistry.registercomponent (' Allen ', () = Allen);

  

In this code, the system automatically creates a component called Allen, and the component is displayed by the registration function of the Appregistry API.

This "Allen" with double quotes means that Allen, behind the name of the app, represents the name of the component to be displayed, so we can create a xxx.js file (a file in React-native is also a component) Then we can register this component here to show what this JS is presenting

Import React, {Component} from ' React '; import {  appregistry,  StyleSheet,  Text,  View} from ' React-native '; import NextPage from  './nextpage ' appregistry.registercomponent (' Allen ', () = NextPage);  Registering components

  

Import React, {Component} from ' React ';//importing React Build Import {//Required build Imports  Appregistry,  StyleSheet,  Text,  View,  Navigator,  touchablehighlight} from ' react-native '; export default class Hellopage extends Component {  // Note: The registered component is only registered once and the component name is irrelevant  and the file component name is about  constructor (props) {    super (props)  }  render () {    const { Navigator} = This.props;    Return (      <view style={{padding:50,borderwidth:1,}}>                 <text Style={{fontsize:50,}}>sds ' d ' f ' d ' sds</text>      </View>    )  }}

  

RN's first API-----Registration component Appregistry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.