RN的第一个API-----注册组件Appregistry

首先解释下AppRegistry是JS运行所有React Native应用的入口  什么是入口?

1.在我们初始化一个react native项目的时候 默认的index.ios.js/index.ios.js里面的内容是这这样的  

(这里我们简化一下代码)

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);

  

这段代码中系统自动创建了一个组件叫做Allen 然后这个组件会被Appregistry 这个API的注册函数显示出来。

   带双引号的这个“Allen”代表的是这个APP的名称 后面的Allen代表的是所要显示的组件名称, 那么我们就可以在创建一个xxx.js文件 (在react-native中一个文件也是一个组件) 那么我们就可以将这个组件注册到这里来 则可以显示这个js所呈现的内容  

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import NextPage  from './NextPage'
AppRegistry.registerComponent('Allen', () => NextPage );  //注册组件

  

import React, { Component } from 'react';//导入react的组建
import {//需要的组建导入
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Navigator,
  TouchableHighlight
} from 'react-native';





export default class HelloPage extends Component {  //注意:注册的组件只是注册一次 和组件名称无关  和文件组件名称有关
  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>
    )
  }
}

  

转载于:https://www.cnblogs.com/allenxieyusheng/p/5775308.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值