开头敲黑板!!
  无论你是RN的新手还是老手,跟着流程走,RN项目搭建起来完全不是问题!
 
一、网址收集
tabbar样式设置:https://www.npmjs.com/package/react-native-navigator
switch网址:https://reactnavigation.cn/docs/switch/
 
二、安装
yarn global add create-react-native-app
create-react-native-app cookbooks
        ? Choose a template: blank
yarn add typescript tslint --dev     可以把ts的错误暴露出来
yarn add @types/react @types/react-native @types/react-dom --dev  react-dom安装后可以基于浏览器使用ts
yarn add concurrently rimraf  react-native-scripts --dev   可以切换环境()端口号的自动分配
yarn add ts-jest @types/jest @types/react-test-renderer --dev
tsc --init    初始化,可以不用该命令,手工创建tsconfig.json文件
                 若使用该命令会自动生成一个tsconfig.js文件,删除里面所有内容,将下面的配置信息完全拷贝过去 
tsconfig.json文件:
{
"compilerOptions": {
"module":"es2015",
"target": "es2015",
"jsx": "react", //jsx要配置成react,默认情况下没有,不然jsx解析会失败
"rootDir": "src", //入口文件夹,默认情况下没有src文件夹,所以还要在项目下创建一个src文件夹进行入口的编译
"outDir": "build", //输出文件夹,ts必须打成一个包,把ts转成js无法运行文件,所以先build再去run,同时加上watch每修改一次build一次
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"sourceMap": true,
"experimentalDecorators": true,
"preserveConstEnums": true,
"allowJs": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"moduleResolution":"Node"
}, "filesGlob": [
"typings/index.d.ts",
"src/**/*.ts",
"src/**/*.tsx",
"node_modules/typescript/lib/lib.es6.d.ts"
], "types": [
"react",
"react-dom",
"react-native"
], "exclude":[ // exclude排除哪些配置项
"build",
"node_modules",
"jest.config.js",
"App.js"
], "compileOnSave": false
}
 
配置package.json文件中的npm expo-cli脚本scripts
package.json文件:
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js",
"lint": "tslint src/**/*.ts",
"tsc": "tsc",
"clean": "rimraf build",
"build": "yarn run clean && yarn run tsc --",
"watch": "yarn run build -- -w",
"watchAndRunAndroid": "concurrently \"yarn run watch\" \"yarn run android\"",
"buildRunAndroid": "yarn run build && yarn run watchAndRunAndroid ",
"watchAndRunIOS": "concurrently \"yarn run watch\" \"yarn run ios\"",
"buildRunIOS": "yarn run build && yarn run watchAndRunIOS ",
"watchAndStart": "concurrently \"yarn run watch\" \"yarn run start\"",
"buildAndStart": "yarn run build && yarn run watchAndStart "
}
修改package.json中的入口文件:
"main":"./node_modules/react-native-scripts/build/bin/crna-entry.js"
此时可以看见node_modules/react-native-scripts/build/bin/crna-entry.js文件中的
var _App = require('../../../../App');

删除App.js的文件内容,粘贴以下内容:

App.js文件:
import App from './build/App';
export default App;

创建一个src文件夹目录,再将babel.config.js文件拖到src文件目录下!

配置完成,可以直接run了 。

yarn buildAndStart

此时会自动生成一个build文件,但里面只有babel.config.js文件,但我们需要让build里有App.js文件
所以需要在src下创建一个App.tsx文件,这时候你可以想写什么就写什么了,当然你也可以用下面的代码试试效果。
App.tsx文件:
import React from "react" import {
View,
Text
} from "react-native"
export default class componentName extends React.Component{
render(){
return(
<View>
<Text>hello world</Text>
</View>
)
}
} 
 
三、tabbar 引入
yarn add react-native-tab-navigator 这个这个可能用到,可能用不到,如果找不到navigation,可以两个都装一下,非常靠谱!
yarn add @types/react-native-tab-navigator
 
四、Swiper引入
yarn add react-native-swiper
注意:引入Swipper的时候,你可能会发现swiper小点点不动了?
这个时候可以联想到nextTick,我们应该等数据来了再渲染,你可以试着判断一下你的渲染数据:
this.list.length>0? 渲染:"null"
 
五、MobX引入
yarn add mobx
yarn add mobx-react    需要在App.tsx中引入provider、store
import { Provider} from "mobx-react"
 
六、路由引入
yarn add  react-navigation@2.18.3     有版本限制,需要注意
yarn add  @types/react-navigation@2.0.24  
import { createStackNavigator } from "react-navigation

七、WebView

import { WebView } from "react-native"
采用原生的方法把H5页面嵌入进去
注意:react-native是用前端技术开发原生APP,它不是混合式开发
 
八、camera引入(引入第三方包都需要提供ts支持)
yarn add @types/expo
import { Text, View, TouchableOpacity } from 'react-native'
import { Camera, Permissions } from 'expo'
Flip:镜头反转
点击拍照可以拿到图片的url,其实图片已经存入本地
react-native可以将所有的硬件设备挂起
 
九、switch引入
import { Switch } from "react-native" 
 
十、AsyncStorage引入
  异步、持久的Key-Value存储系统
import { AsyncStorage } from "react-native"
await AsyncStorage.setItem('isShowMap', `${value}`);    // 第二个参数是字符串
const isShowMap =  Boolean(await AsyncStorage.getItem('isShowMap'));   // 返回值是一个字符串,需要转化为Boolean类型

十一、上拉刷新、下拉加载 -- FlatList引入  

import { FlatList } from "react-native"

上面只规整了import引入的方式,具体代码格式大家可以进RN官网再去看一下,当然!文章最上头有规整好网址,大家copy代码就能很happy的run了。

恩。RN就整理到这里,希望能帮助到大家。

React-native完整配置流程的更多相关文章

  1. React Native之配置URL Scheme(iOS Android)

    React Native之配置URL Scheme(iOS Android) 一,需求分析 1.1,需要在网站中打开/唤起app,或其他app中打开app,则需要设置URL Scheme.比如微信的是 ...

  2. 史上最全Windows版本搭建安装React Native环境配置

    史上最全Windows版本搭建安装React Native环境配置 配置过React Native 环境的都知道,在Windows React Native环境配置有很多坑要跳,为了帮助新手快速无误的 ...

  3. 史上最详细Windows版本搭建安装React Native环境配置 转载,比官网的靠谱亲测可用

    史上最详细Windows版本搭建安装React Native环境配置   2016/01/29 |  React Native技术文章 |  Sky丶清|  95条评论 |  33530 views ...

  4. React Native环境配置

    React Native环境配置 史上最全Windows版本搭建安装React Native环境配置 配置过React Native 环境的都知道,在Windows React Native环境配置有 ...

  5. React Native环境配置之Windows版本搭建

    接近年底了,回想这一年都做了啥,学习了啥,然后突然发现,这一年买了不少书,看是看了,就没有完整看完的.悲催. 然后,最近项目也不是很紧了,所以抽空学习了H5.自学啃书还是很无趣的,虽然Head Fir ...

  6. react-native学习笔记--史上最详细Windows版本搭建安装React Native环境配置

    参考:http://www.lcode.org/react-native/ React native中文网:http://reactnative.cn/docs/0.23/android-setup. ...

  7. windows 7下React Native环境配置

    React Native 是 Facebook 推出的一个用 Java 语言就能同时编写 ios,android,以及后台的一项技术,它可以做到实时热更新 .FaceBook 也号称这们技术是 “Le ...

  8. react native 环境配置

    1. 安装Homebrew Homebrew主要用于安装后面需要安装的watchman.flow 打开MAC的终端,输入如下命令: ruby -e "$(curl -fsSL https:/ ...

  9. React Native环境配置和简单使用

    # 前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会 ...

  10. React Native Android配置部署踩坑日记

    万事开头难 作为一只进入ECMAScript世界不久的菜鸟,已经被React Native的名气惊到了,开源一周数万星勾起了我浓烈的兴趣.新年新气象,来个HellWorld压压惊吧^_^(故意少打个' ...

随机推荐

  1. 循环结构 : while .. for

    # ###循环结构 : while .. for ''' while 循环 可以提高代码的效率,减少代码的冗余 while 条件表达式: code1 code2 如果条件表达式成立,返回True , ...

  2. struts 2.5配置

    1.jar包的变动 必需jar包,旧版本: 必需jar包,新版本: 在struts-2.5.16版本的lib目录下没有xwork-core的jar包,原因是被合并到struts-core这个jar里了 ...

  3. STM32_DAC之软件触发(Trigger)

    stm32_DAC可以用来输出固定的电压值,有些时候需要按键可调输出的电压值.其中一种方法是使用外部中断EXTI9, 另外一种方法就是使用软件触发. 如果将DAC_InitTypeDef.DAC_Tr ...

  4. Java课堂测试——一维数组

    题目: 一个典型的流程是: 2. 用户这时候有两个选择2.1  按 单步执行 键, 在 GUI 看到你的程序是如何一步一步算出目前最大子数组的范围,当前计算到的临时子数组是在哪里,等等. 最好用不同的 ...

  5. “QObject调用moveToThread()后 该如何释放”及QThread 的启动关闭

    1 QThread *thread = new QThread( ); 2 Task *task = new Task(); 3 task->moveToThread(thread); 4 co ...

  6. php魔术变量以及命名空间

    魔术变量: PHP 向它运行的任何脚本提供了大量的预定义常量. 不过很多常量都是由不同的扩展库定义的,只有在加载了这些扩展库时才会出现,或者动态加载后,或者在编译时已经包括进去了. 有八个魔术常量它们 ...

  7. 从网卡发送数据再谈TCP/IP协议—网络传输速度计算-网卡构造

    在<在深谈TCP/IP三步握手&四步挥手原理及衍生问题—长文解剖IP>里面提到 单个TCP包每次打包1448字节的数据进行发送(以太网Ethernet最大的数据帧是1518字节,以 ...

  8. php配置可被设定范围

    PHP中的每个指令都有其所属的模式,这些模式决定这一个PHP指定在何时何地.是否能被设定.例如有些指令可以在 PHP 脚本中用 ini_set() 来设定,而有些则只能在php.ini 或 httpd ...

  9. 基于PLC1850平台的UDP报文接收与发送

    一.UDP报文格式 源端口(2个字节):发送报文的进程的16位端口号. 目的端口(2个字节):目的设备上的接收进程的16位端口号. 长度(2个字节):整个UDP数据报的长度,包括首都和数据字段. 校验 ...

  10. 在sparkStreaming实时存储时的问题

    1.实时插入mysql时遇到的问题,使用的updateStaeBykey有状态的算子 必须设置checkpoint  如果报错直接删掉checkpoint 在创建的时候自己保存偏移量即可 再次启动时读 ...