React Native项目结构
2017-10-03 09:34
393 查看
一、概念
在react-native项目中包含了android和ios的完整的项目结构,可以通过android studio和xcode进行打开和运行,所以可以通过webstorm直接打开react-native的整个项目,然后通过android studio进行打开android项目,用android studio编译运行,在webstorm进行开发。![](https://i.imgur.com/UCdNOcm.png)
二、react native项目结构
android文件夹有完整的android项目,可以使用android studio打开,ios文件夹有完整的ios项目,可以用xcode打开。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);
class hello_world extends Component:创建APP,并且在render函数中返回UI界面结构。这是定义了一个hello_world的类,里面只有一个渲染函数。
const styles = StyleSheet.create:创建CSS样式
AppRegistry.registerComponent(‘hello_world’, () => hello_world);这个才是JS 程序的入口。即把当前APP的对象注册到AppRegistry组件中, AppRegistry组件是js module。
相关文章推荐
- RN(react native)入坑指南-06,项目开发结构(代码分层组织)
- ReactNative项目结构解析
- react-native之项目结构分析
- react-native 项目实战 -- 新闻客户端(1) -- 初始化项目结构
- ReactNative--项目创建及结构分析
- react-native 基础开发二 项目结构和基础代码结构
- 下载及运行Github的React Native开源项目
- React-Native 写的小项目Demo Gank.io
- 关于React Native项目在android上UI性能调试实践
- 现有Android项目引入ReactNative
- react-native与node.js后台项目(1)后台配置
- react native新建项目运行在安卓设备上
- react native项目编译的收报错:方法不会覆盖或实现超类型的方法
- React-Native 之 项目实战(五)
- React Native 集成到 Android 原生项目中踩坑记录 (Didn't find class "com.facebook.jni.IteratorHelper")
- React Native嵌入Android原生项目中(两种方法)
- React Native集成到现有Android Studio项目
- React-Native 之 项目实战(三)
- react-native 项目实战 -- 新闻客户端(7) -- 新闻详情页
- React-Native坑1:Invariant Violation:Application 项目名 has not been registered.