Reat-Native拓展

腾讯微信小程序

注:手机QQ未来也预期会开放一套类似的开放平台

React Native

没有公开的文档在说明,但据打听和一些资料显示手机QQ和手机QQ浏览器都不同程度使用了 React
Native,QQ浏览器是在首页的feed流使用了RN;其中手机QQ团队应该还在自研一套动态化技术方案(柏拉图),未来会开放。

百度轻应用

百度在 2013 年百度世界大会上宣布推出“轻应用”(Light App),百度提供了配套基础设施将移动网站快速转化成轻应用。轻应用本质上是
WebApp,类似微信的公众平台,用户体验受当年手机性能的极大制约,以至于后来日渐式微。

React Native → HtmlNative

贴吧微粉2016年曾经全量采用 React Native,在去年爆发 Facebook 协议事件之后,百度内部出现了大量替代 React Native
的轮子,重写了部分涉及协议冲突的组件。目前手机百度采用 HtmlNative 方案,定制了 Webkit 的增强版。

京东-JDReact

京东采用 React Native 的定制方案 JDReact,对 React Native
的核心库做了裁剪和二次开发,搭建了后台功能支撑平台,同时结合京东的业务特点封装了包括 UI 在内的公共组件库,实现了三端融合,目前已经推广到了20多个业务。

携程-Ctrip React Native

携程采用 React Native 的定制方案 CRN(Ctrip React Native),从2016年4月份开始,携程开始小范围使用 React
Native,实现了站内信和机票低价订阅,随后开始大规模在各个 BU 推广,有超过15 个业务模块在使用,涉及页面在50个以上,据称已经达到了 85%
的双端代码复用率。

去哪儿-Qunar React Native

去哪儿采用 React Native 的定制方案 QRN(Qunar React
Native),抹平了平台差异,降低了开发成本,广泛应用于机票、酒店等核心业务,据称已经达到了 95% 的双端代码复用率。

艺龙-Enjoy React Native

艺龙采用 React Native 的定制方案 ERN,基于 web → Native 的思路,将纯 Html 标签转换为 Native
组件,从而抹平了平台差异,降低开发成本。

React-Native页面优化实践

生产环境下日志输出禁用

接入babel-plugin-transform-remove-console

1
npm install babel-plugin-transform-remove-console --save-dev

配置.babelrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 生产环境下配置去掉console输出



{



  ...



  "plugins": [



    ...



  ],



  "env": {"production": {



      "plugins": [["transform-remove-console", {"exclude": ["error"]}]]



  }



  }



}

采用setNativeProps

在RN中,如果需要频繁刷新view,建议使用setNativeProps,避免使用setState导致的频繁render。

类似顶部tab的透明度渐变,就适用这种情况

官方原文建议

在(不得不)频繁刷新而又遇到了性能瓶颈的时候。
直接操作组件并不是应该经常使用的工具。一般来说只是用来创建连续的动画,同时避免渲染组件结构和同步太多视图变化所带来的大量开销。setNativeProps
是一个“简单粗暴”的方法,它直接在底层(DOM、UIView等)而不是React组件中记录state,这样会使代码逻辑难以理清。所以在使用这个方法之前,请尽量先尝试用setState
和shouldComponentUpdate方法来解决问题。

使用PureComponent或shouldComponentUpdate

PureComponent

当组件更新时,如果组件的 props 和 state 都没发生改变, render 方法就不会触发,省去 Virtual DOM
的生成和比对过程,达到提升性能的目的。

具体原理是 在shouldComponentUpdate回调中,对oldState和newState 及
oldProps和newProps进行浅比较,如不同,才return true,进而回调render。

重写shouldComponentUpdate

代码块

1
2
3
4
5
6
7
8
9
shouldComponentUpdate() {



     return this.state.update;



}

控制在需要的时候才去刷新,根据需求或者业务去控制。

Android硬件加速

通过启用View的renderToHardwareTextureAndroid属性
为true,可以开启View的硬件加速。(决定这个视图是否要把它自己(以及所有的子视图)渲染到一个 GPU 上的硬件纹理中。)

在 Android
上,这对于只修改不透明度、旋转、位移、或缩放的动画和交互十分有用:在这些情况下,视图不必每次都重新绘制,显示列表也不需要重新执行。纹理可以被重用于不同的参数。负面作用是这会大量消耗显存,所以当交互/动画结束后应该把此属性设置回
false。

shouldRasterizeIOS 在iOS上有个 shouldRasterizeIOS属性,
可以设置该view在被渲染到屏幕之前,先绘制到一个位图上,这个我理解和Android中的双缓冲区比较想像。

这个属性对于不会修改组件和子视图尺寸的动画和交互十分有用。举例来说,当我们移动一个静态视图的位置的时候,预渲染允许渲染器重用一个缓存了静态视图的位图,并快速合成。

长列表加载

使用用复用性更强的FlatList或SectionList

FlatList或SectionList优化:

Item采用PureComponent或重写shouldComponentUpdate

getItemLayout如果行高是固定的,可以使用getItemLayout,避免动态测量内容尺寸的开销。

首屏进入时间优化

减少bundle包大小

图片压缩;

图片上传到图片服务器,再引用;

mrn团队的拆包策略(目前有bug)

懒加载

JS在执行import时有时很需要时间,首屏不需要展示的组件可以懒加载

代码块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React, { Component } from 'react';



import { TouchableOpacity, View, Text } from 'react-native';



// 先把这个组件赋值为null



let VeryExpensive = null;



export default class Optimized extends Component {



  state = { needsExpensive: false };



  didPress = () = {



    if (VeryExpensive == null) {



    // 真正需要这个组件的时候才加载



      VeryExpensive = require('./VeryExpensive').default;



    }



    this.setState(() = ({



      needsExpensive: true,



    }));



  };



  render() {



    return (



      <View style={{ marginTop: 20 }}



        <TouchableOpacity onPress={this.didPress}



          <TextLoad</Text



        </TouchableOpacity



      // 根据需要判断是否渲染该组件



        {this.state.needsExpensive ? <VeryExpensive / : null}



      </View



    );



  }



}

React-Native常用三方组件库大全

作者整理的一套常用的React
Native开发中使用到的三方组件库大全,后续也会持续更新,同学们如果发现有好用的组件但是文章中没有列出的,也请给作者留言告知组件名称,作者好将读者们反馈的组件添加到文章中,以便帮助更多的RN开发者。后续持续更新的三方组件会放到文章的开头部分,代表是新追加的组件,小伙伴们请知晓!

如果小伙伴们想学习React Native 框架的搭建以及Redux框架的学习使用,可以参考作者的开源项目OneM:
https://github.com/guangqiang-liu/OneM 记得给个star哦

当然也欢迎小伙伴们加入作者的React Native实战开发QQ交流群:620792950, 开发中遇到的问题可以在群里随意的提问,互相交流学习。

react-native -30 (每天一个Demo,共三十个,有些demo很不错哦)

https://github.com/fangwei716/30-days-of-react-native

自动管理Timer组件

此组件目前只支持ES5 语法,ES6语法

请在componentWillUnmount() 中清除timer

https://github.com/reactjs/react-timer-mixin

蚂蚁金服组件库 antd-mobile

https://github.com/ant-design/ant-design-mobile

react-native-button

https://github.com/ide/react-native-button

点击图片放大缩小

https://github.com/ascoders/react-native-image-viewer

进度组件

https://github.com/oblador/react-native-progress

路由组件react-native-router-flux

https://github.com/aksonov/react-native-router-flux

简单的storage封装

https://github.com/jasonmerino/react-native-simple-store

tabBar组件react-native-tab-navigator

https://github.com/happypancake/react-native-tab-navigator

iconFont组件

https://github.com/oblador/react-native-vector-icons

分页组件 react-native-viewpager

https://github.com/race604/react-native-viewpager

导航组件 react-navigation

https://github.com/react-community/react-navigation

动画

https://github.com/oblador/react-native-animatable

轮播

https://github.com/nick/react-native-carousel

倒计时

https://github.com/buhe/react-native-countdown

设备信息react-native-device-info

https://github.com/rebeccahughes/react-native-device-info

文件上传react-native-fileupload

https://github.com/PhilippKrone/react-native-fileupload

图标

https://github.com/corymsmith/react-native-icons

https://github.com/oblador/react-native-vector-icons

图片选择器react-native-image-picker

https://github.com/react-community/react-native-image-picker

iOS KeyChain管理react-native-keychain

https://github.com/oblador/react-native-keychain

滚轮选择器react-native-picker

https://github.com/beefe/react-native-picker

Android 滚轮选择器react-native-picker-Android

https://github.com/beefe/react-native-picker-android

可刷新列表react-native-refreshable-listview

https://github.com/jsdf/react-native-refreshable-listview

可滚动标签react-native-scrollable-tab-view

https://github.com/skv-headless/react-native-scrollable-tab-view

侧栏react-native-side-menu

https://github.com/react-native-community/react-native-side-menu

轮播react-native-swiper

https://github.com/leecade/react-native-swiper

音视频播放react-native-video

https://github.com/react-native-community/react-native-video

分页浏览react-native-viewpager

https://github.com/race604/react-native-viewpager

可滑动的底部或上部导航栏框架react-native-scrollable-tab-view

https://github.com/skv-headless/react-native-scrollable-tab-view

底部或上部导航框架(不可滑动)react-native-tab-navigator

https://github.com/happypancake/react-native-tab-navigator

CheckBoxreact-native-check-box

https://github.com/crazycodeboy/react-native-check-box

启动白屏问题react-native-splash-screen

https://github.com/crazycodeboy/react-native-splash-screen

简易路由跳转框架react-native-simple-router

https://github.com/react-native-simple-router-community/react-native-simple-
router

持久化存储react-native-storage

https://github.com/sunnylqm/react-native-storage

分类ListViewreact-native-sortable-listview

https://github.com/deanmcpherson/react-native-sortable-listview

将 HTML 目录作为本地视图的控件,其风格可以定制react-native-htmlview

https://github.com/jsdf/react-native-htmlview

Toastreact-native-easy-toast

https://github.com/crazycodeboy/react-native-easy-toast

material组件库(各种漂亮的小组件)

https://github.com/xinthink/react-native-material-kitbase

组件库(各种封装不错的小组件)

http://nativebase.io/docs/v0.4.6/components#anatomy

https://github.com/GeekyAnts/NativeBase

按钮

https://github.com/mastermoo/react-native-action-button

https://github.com/ide/react-native-button

输入框表单验证

https://github.com/gcanti/tcomb-form-native

https://github.com/FaridSafi/react-native-gifted-form

https://github.com/bartonhammond/snowflake

炫酷效果的 TextInput

https://github.com/halilb/react-native-textinput-effects

https://github.com/zbtang/React-Native-TextInputLayout

聊天

https://github.com/FaridSafi/react-native-gifted-chat

地图

https://github.com/lelandrichardson/react-native-maps

动画

https://github.com/oblador/react-native-animatable

加载动画

https://github.com/maxs15/react-native-spinkit

抽屉效果

https://github.com/root-two/react-native-drawer

侧滑按钮

https://github.com/dancormier/react-native-swipeout

https://github.com/jemise111/react-native-swipe-list-view

图表

https://github.com/tomauty/react-native-chart

下拉放大

https://github.com/lelandrichardson/react-native-parallax-view

可滑动的日历组件

https://github.com/cqm1994617/react-native-myCalendar

语言转化和一些常用格式转换

https://github.com/joshswan/react-native-globalize

单选多选ListView

https://github.com/hinet/react-native-checkboxlist

选择按钮

https://github.com/sconxu/react-native-checkbox

二维码

https://github.com/ideacreation/react-native-barcodescanner

制作本地库

https://github.com/frostney/react-native-create-library

影音相关

https://github.com/MisterAlex95/react-native-record-sound

安卓录音

https://github.com/bosung90/react-native-audio-android

提示消息的Bar

https://github.com/KBLNY/react-native-message-bar

iOS原生TableView

https://github.com/aksonov/react-native-tableview

点击弹出视图

https://github.com/jeanregisser/react-native-popover

https://github.com/instea/react-native-popup-menu

3D Touch

https://github.com/madriska/react-native-quick-actions

双平台兼容的ActionSheet

https://github.com/beefe/react-native-actionsheet

照片墙

https://github.com/ldn0x7dc/react-native-gallery

键盘遮挡问题

https://github.com/wix/react-native-keyboard-aware-scrollview

https://github.com/reactnativecn/react-native-inputscrollview

本地存储

https://github.com/sunnylqm/react-native-storage

星星

https://github.com/djchie/react-native-star-rating

国际化

https://github.com/joshswan/react-native-globalize

扫描二维码

https://github.com/lazaronixon/react-native-qrcode-reader

通讯录

https://github.com/rt2zz/react-native-contacts

加密

https://www.npmjs.com/package/crypto-js

缓存管理

https://github.com/reactnativecn/react-native-http-cache

ListView的优化

https://github.com/sghiassy/react-native-sglistview

图片和base64互转

https://github.com/xfumihiro/react-native-image-to-base64

安卓 iOS 白屏解决

https://github.com/mehcode/rn-splash-screen

Text跑马灯效果

https://github.com/remobile/react-native-marquee-label

清除按钮的输入框

https://github.com/beefe/react-native-textinput

webView-bridge相关

https://github.com/alinz/react-native-webview-bridge

判断横竖屏

https://github.com/yamill/react-native-orientation

PDF

https://github.com/cnjon/react-native-pdf-view

获取设备信息

https://github.com/rebeccahughes/react-native-device-info

手势放大缩小移动

https://github.com/kiddkai/react-native-gestures

https://github.com/johanneslumpe/react-native-gesture-recognizers

下拉-上拉-刷新

https://github.com/FaridSafi/react-native-gifted-listview

https://github.com/jsdf/react-native-refreshable-listview

https://github.com/greatbsky/react-native-pull/wiki

下拉选择

https://github.com/alinz/react-native-dropdown

图片查看

https://github.com/oblador/react-native-lightbox

照片选择

https://github.com/marcshilling/react-native-image-picker

https://github.com/ivpusic/react-native-image-crop-picker

图片加载进度条

https://github.com/oblador/react-native-image-progress

轮播视图

https://github.com/race604/react-native-viewpager

https://github.com/FuYaoDe/react-native-app-intro

https://github.com/appintheair/react-native-looped-carousel

https://github.com/leecade/react-native-swiper

模态视图

https://github.com/maxs15/react-native-modalbox

https://github.com/brentvatne/react-native-modal

https://github.com/bodyflex/react-native-simple-modal

毛玻璃效果

https://github.com/react-native-fellowship/react-native-blur

头像库

https://github.com/oblador/react-native-vector-icons

滑动选项卡

https://github.com/skv-headless/react-native-scrollable-tab-view

文件上传

https://github.com/aroth/react-native-uploader

动画

https://github.com/oblador/react-native-animatable

图标

https://github.com/oblador/react-native-vector-icons

图片选择器(可多选)

https://github.com/ivpusic/react-native-image-crop-picker

滚轮选择器

https://github.com/beefe/react-native-picker

下拉刷新listview

https://github.com/jsdf/react-native-refreshable-listview

可滚动Tab

https://github.com/skv-headless/react-native-scrollable-tab-view

侧栏

https://github.com/react-native-community/react-native-side-menu

图片轮播

https://github.com/leecade/react-native-swiper

CheckBox

https://github.com/crazycodeboy/react-native-check-box

Toast

https://github.com/crazycodeboy/react-native-easy-toast

各种漂亮的小组件

https://github.com/xinthink/react-native-material-kit

base组件库

https://github.com/GeekyAnts/NativeBase

按钮

https://github.com/mastermoo/react-native-action-button

炫酷效果的 TextInput

https://github.com/halilb/react-native-textinput-effects

https://github.com/zbtang/React-Native-TextInputLayout

聊天

https://github.com/FaridSafi/react-native-gifted-chat

百度地图

https://github.com/lovebing/react-native-baidu-map

http://www.jianshu.com/p/eceb7e66fa5e

加载动画

https://github.com/maxs15/react-native-spinkit

侧滑按钮

https://github.com/dancormier/react-native-swipeout

https://github.com/jemise111/react-native-swipe-list-view

图表

https://github.com/wuxudong/react-native-charts-wrapper

下拉放大

https://github.com/lelandrichardson/react-native-parallax-view

可滑动的日历组件

https://github.com/cqm1994617/react-native-myCalendar

提示消息的Bar

https://github.com/KBLNY/react-native-message-bar

点击弹出视图

https://github.com/jeanregisser/react-native-popover

3D Touch

https://github.com/madriska/react-native-quick-actions

双平台兼容的ActionSheet

https://github.com/beefe/react-native-actionsheet

图片加载进度条

https://github.com/oblador/react-native-image-progress

模态视图

https://github.com/maxs15/react-native-modalbox

https://github.com/bodyflex/react-native-simple-modal

毛玻璃效果

https://github.com/react-native-community/react-native-blur

按钮特效

https://github.com/dwicao/react-native-circle-button

折叠动画

https://github.com/jmurzy/react-native-foldview

方块滚动轮播图

https://github.com/archriss/react-native-snap-carousel

下拉选项组件

https://github.com/sohobloo/react-native-modal-dropdown

提示气泡toast

https://github.com/magicismight/react-native-root-toast

From表单

https://github.com/FaridSafi/react-native-gifted-form

线性渐变颜色

https://link.jianshu.com/?t=https://github.com/brentvatne/react-native-linear-
gradient

app 引导页

https://github.com/fuyaode/react-native-app-intro

手势解锁密码

https://link.jianshu.com/?t=https://github.com/spikef/react-native-gesture-
password

瀑布流列表

https://github.com/xudafeng/autoresponsive-react-native

折叠列表

https://github.com/naoufal/react-native-accordion

通讯录

https://github.com/i6mi6/react-native-alphabetlistview

多级菜单

https://github.com/vczero/react-native-tab-menu

tip提示框

https://github.com/chirag04/react-native-tooltip

pdf文件上传

https://link.jianshu.com/?t=https://github.com/wonday/react-native-pdf

https://github.com/christopherdro/react-native-html-to-pdf

上传doc文档

https://github.com/philipphecht/react-native-doc-viewer

列表滑动删除

https://github.com/jemise111/react-native-swipe-list-view

IM聊天界面

https://github.com/Ice-MT/react-native-imUI

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×