React Native常用第三方库
前言
React Native出来一年多了,受到各大开发人员的喜爱,但是由于只是专注于View层的开发,因此在很多深层次上还需要结合原生app做一定的兼容,还有就是现在好多控件,如Android中已是系统的控件的sidemenu、checkbox、gridview等,这些在react native中 系统是没有给我们提供的,这时候就借助了第三方开源的力量。
那么我们今天说说在React Native项目开发中常见的一些第三方库。
常见的第三方库
组件篇
CheckBox(多选按钮)
react-native-check-box CheckBox
基本用法:
<CheckBox style= onClick={()=>this.onClick(data)} isChecked={data.checked} leftText={leftText} />;
当然我们也可以自定义样式,主要是对选中和未选中的样式做修改:
renderCheckBox(data) { var leftText = data.name; return ( <CheckBox style= onClick={()=>this.onClick(data)} isChecked={data.checked} leftText={leftText} checkedImage={<Image source={require('../../page/my/img/ic_check_box.png')} style={this.props.theme.styles.tabBarSelectedIcon}/>} unCheckedImage={<Image source={require('../../page/my/img/ic_check_box_outline_blank.png')} style={this.props.theme.styles.tabBarSelectedIcon}/>} />); }
RadioButton(单选按钮)
react-native-flexi-radio-button
使用也很简单,就是在中嵌套下就行:
<RadioGroup onSelect = {(index, value) => this.onSelect(index, value)} > <RadioButton value={'item1'} > <Text>This is item #1</Text> </RadioButton> <RadioButton value={'item2'}> <Text>This is item #2</Text> </RadioButton> <RadioButton value={'item3'}> <Text>This is item #3</Text> </RadioButton> </RadioGroup>
sidemenu (侧滑栏)
react-native-side-menu
使用:
<SideMenu menu={menu}> <ContentView/> </SideMenu>
splashscreen
react-native-splash-screen
使用也很简单,就是添加一个闪屏的xml
imagepicker
这个组件帮助我们选取图片和调用相机等,这个组件同时支持photo和video,也就是照片和视频都可以用这个组件实现。
用法:
import ImagePickerManager from ‘NativeModules‘; var options = { title: ‘Select Avatar‘, // 选择器的标题,可以设置为空来不显示标题 cancelButtonTitle: ‘Cancel‘, takePhotoButtonTitle: ‘Take Photo...‘, // 调取摄像头的按钮,可以设置为空使用户不可选择拍照 chooseFromLibraryButtonTitle: ‘Choose from Library...‘, // 调取相册的按钮,可以设置为空使用户不可选择相册照片 customButtons: { ‘Choose Photo from Facebook‘: ‘fb‘, // [按钮文字] : [当选择这个按钮时返回的字符串] }, mediaType: ‘photo‘, // ‘photo‘ or ‘video‘ videoQuality: ‘high‘, // ‘low‘, ‘medium‘, or ‘high‘ durationLimit: 10, // video recording max time in seconds maxWidth: 100, // photos only默认为手机屏幕的宽,高与宽一样,为正方形照片 maxHeight: 100, // photos only allowsEditing: false, // 当用户选择过照片之后是否允许再次编辑图片 }; ImagePickerManager.showImagePicker(options, (response) => { console.log(‘Response = ‘, response); if (response.didCancel) { console.log(‘User cancelled image picker‘); } else if (response.error) { console.log(‘ImagePickerManager Error: ‘, response.error); } else if (response.customButton) { // 这是当用户选择customButtons自定义的按钮时,才执行 console.log(‘User tapped custom button: ‘, response.customButton); } else { // You can display the image using either data: if (Platform.OS === ‘android‘) { source = {uri: response.uri, isStatic: true}; } else { source = { uri: response.uri.replace(‘file://‘, ‘‘), isStatic: true }; } this.setState({ avatarSource: source }); } });
然后在页面展示的时候:
<Image source={this.state.avatarSource} style={styles.uploadAvatar} />
说到这里,我们要说一下另一个控件picker
picker-Android
Picker就是ReactNative界的Spinner,其常用的属性有:
- onValueChange 这个方法在方法在选择Picker某一项时调用 可传两个参数 选择的value和position
- selectedValue 这个属性是选择的值
- enabled 设置是否可点击 Android属性
- mode 设置样式 Android属性 dropdown下拉样式和dialog弹窗样式 默认是dialog
- prompt 设置Picker标题 Android属性 并且只有是mode为dialog才会显示
- itemStyle 设置每一项的样式 iOS属性
用法:
/** * Created by Administrator on 2016/9/7. */ import React, {Component} from 'react'; import { AppRegistry, View, Picker, } from 'react-native'; class PickerG extends Component { constructor(porp) { super(porp); this.state= { selectedValue: '' } } render() { return ( <Picker //Picker样式 dialog弹窗样式默认 dropdown显示在下边 // mode = {'dropdown'} //显示选择内容 selectedValue={this.state.selectedValue} //选择内容时调用此方法 onValueChange={(value)=>this.setState({selectedValue: value})} //设置Title 当设置为dialog时有用 prompt={'请选择'} > <Picker.Item label='Android' value='android'/> <Picker.Item label='IOS' value='ios'/> <Picker.Item label='ReactNative' value='reactnative'/> </Picker> ) } } module.exports = PickerG;
easy-toast
react-native-easy-toast
这个组件兼容了Android和iOS的toast,使用也很简单。
用法:
render() { return ( <View style={styles.container}> ... <Toast ref="toast"/> </View> ); }
最后在需要调用的地方:
this.refs.toast.show('hello world!');
其他的第三方库
选项卡
各种漂亮的小组件
按钮
输入框表单验证
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
聊天表情
地图
动画
加载动画
日历
可多选的Listview
react-native-uploader //文件上传
react-native-image-picker 图片选择器
react-native-keychain iOS KeyChain管理
react-native-picker滚轮选择器
react-native-picker-Android Android 滚轮选择器
react-native-refreshable-listview 可刷新列表
react-native-scrollable-tab-view 可滚动标签
react-native-video 视频播放
react-native-scrollable-tab-view 可滑动的底部或上部导航栏框架
react-native-tab-navigator 底部或上部导航框架(不可滑动)
react-native-check-box CheckBox多选
react-native-splash-screen 启动白屏问题
react-native-simple-router 简易路由跳转框架
react-native-storage 持久化存储
react-native-sortable-listview 分类ListView
react-native-htmlview 将 HTML 目录作为本地视图的控件,其风格可以定制
react-native-easy-toast 一款简单易用的 Toast 组件
react-native-tab-navigator 选项卡
react-native-material-kit 漂亮的小组件
NativeBasebase组件库(各种封装不错的小组件)
不错的按钮:
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/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/react-native-fellowship/react-native-side-menu
侧滑按钮
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/reactnativecn/react-native-inputscrollview
https://github.com/wix/react-native-keyboard-aware-scrollview
本地存储
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相关
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
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Eclipse编译带so库或jar包的android应用
使用Eclipse build APK文件,只要将so文件放在与src平级的地方创建目录结构libs/armeabi,文件名格式如:libs/armeabi/libxxx.so. eclipse在打包的时候会根据文件名的命名规则(lib****.so)去打包so文件,开头和结尾必须分别为“lib”和“.so”,否则是不会打包到apk文件中的 将so库编进apk 在源码目录中建立libs/armeabi/,然后将libxxx.so拷到该目录下即可编到apk包中(apk生成在bin目录下),可以试用unzip将apk解包看看lib是否存在。 编译出来的 共享库,会自动 添加 一个 .so 后缀,如: libhello-jni.so 在android的Java代码里添加: static { System.loadLibrary("hello-jni");//注意 千万 不要 在 前面 加 lib 后面 加 so }
- 下一篇
Android风格与主题
Android xml风格和主题文件的编写,是涉及到整个程序界面美观的因素之一。较好的应用风格和主题,可以实现美观而统一的界面,这就犹如Web开发中的CSS。 Styles和Themes都是资源,存放在res/values文件夹下。 什么是Style,什么是Theme? Style:是一个包含一种或者多种格式化属性的集合,我们可以将其用为一个单位用在布局XML单个元素当中。比如,我们可以定义一种风格来定义文本的字号大小和颜色,然后将其用在View元素的一个特定的实例。 Theme:是一个包含一种或者多种格式化属性的集合,我们可以将其为一个单位用在应用中所有的Activity当中或者应用中的某个Activity当 中。比如,我们可以定义一个Theme,它为window frame和panel 的前景和背景定义了一组颜色,并为菜单定义可文字的大小和颜色属性,可以将这个Theme应用在你程序当中所有的Activity里。 Style和Theme的XML文件结构 对每一个Styles和Themes,给<style>元素增加一个全局唯一的名字,也可以选择增加一个父类属性。在后边我们可...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- 设置Eclipse缩进为4个空格,增强代码规范
- Mario游戏-低调大师作品
- MySQL8.0.19开启GTID主从同步CentOS8
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- CentOS8编译安装MySQL8.0.19
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2整合Redis,开启缓存,提高访问速度