閱讀1030 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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-animatable 動畫

react-native-carousel 輪播

react-native-countdown 倒計時

react-native-device-info設備信息

react-native-icons 圖標

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-side-menu 側欄

react-native-swiper 輪播

react-native-video 視頻播放

react-native-viewpager 分頁瀏覽

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

最後更新:2017-05-05 18:50:43

  上一篇:go Redis開發運維實踐數據操作之集合操作
  下一篇:go Redis開發運維實踐數據操作之字符串操作