美文网首页
React Native系列【目录结构】

React Native系列【目录结构】

作者: 老鱼_chaimyu | 来源:发表于2019-04-14 22:25 被阅读0次

本文仅用来记录个人安装过程备忘

目录结构

React Native系列【mac下环境搭建】文章中已经建立了一个测试程序,来看看生成的项目结构:

image.png

分别看下几个目录和主要文件,其它.xxx文件基本都是一些配置,很少需要改动

android

支持Android的文件

ios

支持iOS的文件

node_modules

各种node库

app.json

配置项目名字和显示名称

{
  "name": "scibeneapp",
  "displayName": "scibeneapp"
}

index.ios.js

iOS的界面布局代码

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

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

export default class scibeneapp 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.ios.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
        <Text style={styles.welcome}>
          I like React Native!
        </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('scibeneapp', () => scibeneapp);

通过import引入库,重点在class scibeneapp的render()函数,里面有<View>、<Text>这种标记,这是JSX语法(在JavaScript中嵌入XML结构的语法)。和HTML类似,<Text>指定一个React Native组件,还有很多其它的组件可以引用进来。

StyleSheet.create()创建了可以使用的网络,可以在组件标签中引用。

最后一行“registerComponent”注册了这个组件。

index.android.js

Android的界面布局代码,和index.ios.js是一样的,可以针对Android做不同处理。

相关文章

网友评论

      本文标题:React Native系列【目录结构】

      本文链接:https://www.haomeiwen.com/subject/vsjewqtx.html