React-Native国际化多语言

库属性介绍

项目地址:<https://github.com/AlexanderZaytsev/react-native-i18n

属性 解释

支持RN版本 所有版本

支持平台 iOS+Android

是否需要NativeModule 是

是否可移植 是

是否含有jni模块 否

使用

1.install(略,git里都写着了,就是npm那些事)

2.项目中使用

因为是一些静态属性引用,所以你用redux做储存替换也可以,直接做饮用也可以(本文拿en,zh为例)。

首先是建英文版本的配置文件,en/index.js

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
exportdefault{



home:{



greeting:'Greeting in en',



tab_home:'Home',



tab_donate:'Donate',



tab_demo:'Demo',



language:'language',



live_demo:'Live Demo',



buy_me_coffee:'Buy me a coffee',



gitee:'Gitee',



star_me:'Star me',



donate:'donate',



exit:'exit?',



},



donate:{



donate:'donate us~~~',



donate_desc:'© 2017 Pactera Technology International Limited. All rights
reserved.',



},



demo:{



dialog:'dialog',



button:'button',



switch:'switch',



action_sheet:'Action Sheet',



}



};

然后是中文的zh/index.js

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
 exportdefault{



home:{



greeting:'Greeting in zh',



tab_home:'首页',



tab_donate:'捐赠',



tab_demo:'例子',



language:'语言',



live_demo:'例子',



buy_me_coffee:'请我一杯coffee',



gitee:'Gitee',



star_me:'关注我',



donate:'贡献',



exit:'是否退出?',



},



donate:{



donate:'支持我们~~',



donate_desc:'© 2017 Pactera Technology International Limited. All rights
reserved.',



},



demo:{



dialog:'提示框',



button:'按钮',



switch:'开关',



action_sheet:'',



}



};

属性名,结构是一致的只是属性不同,当然这里是静态的2个文件,如果场景需要可以服务端下发json,那就是完全动态的了,这部分看业务需求了。

默认的语言环境

我们在上面写了2种语言配置,那么哪种作为初始化的呢?在业务层调用前,我们可以先进行预设

i18n/index.js

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
import i18nfrom'react-native-i18n';



import enfrom'./en';



import zhfrom'./zh';



i18n.defaultLocale ='en';



i18n.fallbacks = true;



i18n.translations = {



en,



zh,



};



export {i18n};

这边进行了一些预设,默认语境为en,允许fallbacks状态(为true时,顺序向下遍历翻译),预设转换的文件就2个,一个en一个zh,这个你也可以自行后续添加根据需求而定。

业务层调用

先是倒包

import {i18n} from ‘你预设的index的目录’;

调用(拿一个Toast做个例子)

ToastAndroid.show(i18n.t(‘home.exit’),ToastAndroid.SHORT);

源码分析

这个库的实现分为2部分,一部分是Native的版本判断等功能以及js部分的核心实现fnando/i18n-js

i18n-js是一个轻量级的js翻译库,他支持各种格式和内容的换算和语言内容的切换,地址如下:<https://github.com/fnando
/i18n-js

那么翻译转换这块是 I18n.js做的那么Native做了些啥呢?我们来一探究竟(以安卓为例,苹果看不懂,抱歉)

Native代码就两个类,所以我之前说你直接把Native代码copy走然后项目依赖I18n.js也能达到这个效果

RNI18nPackage是一个普通的Package类,它的作用就是把我们的module加到主应用的getPackages()方法中的列表里,然后一起打进包里而已。

具体功能都在RNI18nModule里

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
publicclassRNI18nModuleextendsReactContextBaseJavaModule{



publicRNI18nModule(ReactApplicationContext reactContext) {



super(reactContext);



}



//RN调用的控件名



@Override



publicStringgetName() {



return"RNI18n";



}



//对取出的Locale列表进行格式化的方法



privateStringtoLanguageTag(Locale locale) {



if(Build.VERSION.SDK_INT = Build.VERSION_CODES.LOLLIPOP) {



returnlocale.toLanguageTag();



}



StringBuilder builder =newStringBuilder();



builder.append(locale.getLanguage());



if(locale.getCountry() !=null) {



builder.append("-");



builder.append(locale.getCountry());



}



returnbuilder.toString();



}



privateWritableArraygetLocaleList() {



WritableArray array = Arguments.createArray();



if(Build.VERSION.SDK_INT = Build.VERSION_CODES.N) {



//获取区域设置列表。这是获取区域的首选方法。



LocaleList locales = getReactApplicationContext()



.getResources().getConfiguration().getLocales();



for(inti =0; i < locales.size(); i++) {



array.pushString(this.toLanguageTag(locales.get(i)));



}



}else{



array.pushString(this.toLanguageTag(getReactApplicationContext()



.getResources().getConfiguration().locale));



}



returnarray;



}



//js端可获取属性的列表



@Override



publicMap<String, ObjectgetConstants() {



HashMap<String, Object constants =newHashMap<String,Object();



constants.put("languages",this.getLocaleList());



returnconstants;



}



//提供给js端调用的方法,用来获取默认的语言环境,回调方式用的是promise



@ReactMethod



publicvoidgetLanguages(Promise promise) {



try{



promise.resolve(this.getLocaleList());



}catch(Exception e) {



promise.reject(e);



}



}



}

加一个toast看下locale会出现什么

Toast.makeText(getReactApplicationContext(),”locales.get(i)
“+locales.get(i),Toast.LENGTH_LONG).show();

本想一探究竟内部的实现,结果是个不公开的类

总结

首先Native那里获取本手机的LocaleList然后格式化取第一个元素交由I18n.js处理,然后I18n.js根据key选用一套有效的语言规则,再之后流程就和使用时候的顺序一样了。

整个库集成难度较低,使用起来比较简便,使用下来没碰到大坑,配合redux更美味。

准备阶段

[react-native-i18n](https://github.com/AlexanderZaytsev/react-native-
i18n)第三方多语言库

安装:yarn add react-native-i18n

[react-native-device-
info](https://www.jianshu.com/p/%5Bhttps://github.com/rebeccahughes/react-
native-device-info%5D(https://github.com/rebeccahughes/react-native-device-
info))用户获取系统本地语言环境

安装:yarn add react-native-device-infoandreact-native link react-native-device-
info

实践阶段:

在项目中创建zh.js、en.js、I18n.js三个js文件,DataRepository.js是一个我自定义的数据持久化类,在这个demo中的作用是存取用户改变后的语言环境,直接拷贝过去就可以用(不是必须的)。

代码分别为:

zh.js

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
exportdefault{



english:'英文',



chinese:'中文',



changeToEnglish:'切换到英文',



changeToChinese:'切换到中文',



changeToSystem:'切换到系统语言',



}

en.js

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
exportdefault{



english:'english',



chinese:'chinese',



changeToEnglish:'change to english',



changeToChinese:'change to chinese',



changeToSystem:'change to System',



}

I18n.js

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
importI18n,{ getLanguages }from'react-native-i18n'



importDeviceInfofrom'react-native-device-info'



importDataRepositoryfrom'../dao/DataRepository'



importenfrom'./en'



importzhfrom'./zh'



I18n.defaultLocale ='en';



I18n.fallbacks =true;



I18n.translations = {



en,



zh,



};



I18n.localeLanguage =()={



newDataRepository().fetchLocalRepository('localLanguage')



.then((res)={



I18n.locale = res;



})



.catch((error)={



I18n.locale = DeviceInfo.getDeviceLocale();



});



returnI18n.locale;



};



export{ I18n, getLanguages };

重点方法、属性讲解

I18n.t(): 使用频率是最高的,举个栗子:

<Textstyle={styles.welcome}

{I18n.t(‘english’)}

</Text

以上I18n.t(‘english’)中的english参数就是在zh.js、en.js文件中的语言配置项

具体显示内容会随着语言环境调用相应的语言配置文件,呈现给用户相应的语言内容。

I18n.getLanguages获取用户首选的语言环境

I18n.locale: 设置本地语言环境。

I18n.defaultLocale首选默认语言

I18n.fallbacks: 看文档说明我理解的意思是:如果获取到的系统语言类似en_USen-GB这样的,插件初始化的时候发现没有en_US.jsen-
GB.js,这个时候如果设置了I18n.fallbacks =
true;系统就会按这样的(en_USen.js)顺序去查找文件,就会去找有一个en.js这样的文件, 官方建议使用I18n.fallbacks =
true;

更多关于i18n-js的属性和方法请点击这里查看

ios需要配置语言环境

使用过程中发现一个刷新的问题:

我在使用过程中发现调用了I18n.locale=‘我设置的语言’后,当前的界面语言并没有改变,而其他界面的语言已经改变了,就比如说我上面截图的侧滑菜单,当我在侧滑菜单切换语言后发现侧滑菜单里面的语言并没有发现变化,而首页的语言环境已经改变了,我不知道为什么,摸索最后找到了一种解决方案(可能不是最佳方案,但是解决了刷新当前界面语言的问题,如果有更好的方法欢迎分享),解决方案:调用一下setState(无论设置的这个state属性在render中有没有被使用,都有效)。
具体代码看App.js,我项目中有使用localeLanguage所以我把改变后的语言存到state中

1
2
3
4
5
6
7
8
9
this.setState({



localeLanguage: I18n.locale



});

请注意,js的名字最好都是语言的缩写,下面提供参考:

突然有个想法看看没有支持的语言会变成什么:看来如果没有支持某种语言就会默认使用英语,我曾经试过分别调换这两个的引入顺序发现结果还是英语

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

BindingX

基于weex / React Native的富交互解决方案。

官网:https://alibaba.github.io/bindingx/

它提供了一种称之为表达式绑定(Expression Binding)的机制可以在 weex
上让手势等复杂交互操作以60fps的帧率流畅执行,而不会导致卡顿,因而带来了更优秀的用户体验 。

简要介绍

由于weex/RN框架底层使用的JS-Native
Bridge具有天然的异步特性,这使得JS和Native之间的通信会有固定的性能损耗,因此在一些复杂的实时交互场景中(如手势),JS
代码很难以高帧率运行,这极大地限制了框架的能力。目前官方并没有很好的方式解决。

而我们通过探索,提出了一种全新的方式用来解决这个问题,方案称之为Expression
Binding。它的核心思想是将”交互行为”以表达式的方式描述,并提前预置到Native从而避免Native与JS频繁通信。

示例展示

下面展示了一部分使用bindingx的示例。您可以下载或者编译我们的playground
app来获取更多的示例。同时,您也可以在我们的在线playground上编写您自己的demo。

注意:Weex支持两种前端写法(rax和vue),链接是直接跳转到Playground。 React-
Native由于目前Playground还不支持,所以直接跳转到源码。

特性

复杂但流畅的交互效果

强大的表达式解析引擎

丰富的缓动函数

文档与教程

https://alibaba.github.io/bindingx/guide/introduce

Your browser is out-of-date!

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

×