React Native项目结构

一、概念

在react-native项目中包含了android和ios的完整的项目结构,可以通过android studio和xcode进行打开和运行,所以可以通过webstorm直接打开react-native的整个项目,然后通过android studio进行打开android项目,用android studio编译运行,在webstorm进行开发。

二、react native项目结构

  1. android文件夹有完整的android项目,可以使用android studio打开,ios文件夹有完整的ios项目,可以用xcode打开。
  2. index.android.js和index.ios.js是入口文件

三、代码流程

(1)、JS入口(以index.android.js为例)

    import React, { Component } from 'react';
    import {
      AppRegistry,
      StyleSheet,
      Text,
      View
    } from 'react-native';

    export default class hello_world extends Component {
      render() {
        return (
          <View style={styles.container}>
            <Text style={styles.welcome}>
              Welcome to React Native!
            </Text>
            <Text style={styles.instructions}>
              To get started, edit index.android.js
            </Text>
            <Text style={styles.instructions}>
              Double tap R on your keyboard to reload,{'\n'}
              Shake or press menu button for dev menu
            </Text>
          </View>
        );
      }
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
      },
    });

    AppRegistry.registerComponent('hello_world', () => hello_world);
  1. class hello_world extends Component:创建APP,并且在render函数中返回UI界面结构。这是定义了一个hello_world的类,里面只有一个渲染函数。
  2. const styles = StyleSheet.create:创建CSS样式
  3. AppRegistry.registerComponent(‘hello_world’, () => hello_world);这个才是JS 程序的入口。即把当前APP的对象注册到AppRegistry组件中, AppRegistry组件是js module。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值