• Stars
    star
    281
  • Rank 147,023 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a universal switch for android and iOS

react-native-switch-pro (2.0 is coming)

version downloads downloads
A universal switch for android and iOS, it could be the best switch for react-native on Github.

Preview

   

Feature

  • Almost perfect switch on react-native
  • Have a good performance on both iOS and Android
  • Add gesture with PanResponder  
  • More animations to follow iOS native performance
  • Support async and sync event
  • Support bidirectional data binding
  • Clear code style

Install

npm install react-native-switch-pro --save

Usage

  • Sync
import Switch from 'react-native-switch-pro'
...
  render() {
    return (
      <View style={styles.container}>
        <Switch onSyncPress={value => {...}}/>
      </View>
    )
  }
...
  • Async
...
  render() {
    return (
      <View style={styles.container}>
        <Switch onAsyncPress={(callback) => {
          You can call your async module and just invoke callback(true) when succeed,  
          callback(false) when fail.
        }}/>
      </View>
    )
  }
...

Props

Name Description Default Type
width width of switch 40 number
height height of switch 21 number
value state of switch which can be used to bidirectional binding undefined bool
disabled whether switch is clickable false bool
circleColorActive color for circle handler of switch when it is on white string
circleColorInactive color for circle handler of switch when it is off white string
style styles that will be applied for switch container undefined style
circleStyle styles that will be applied for the circle undefined style
backgroundActive color of switch when it is on green string
backgroundInactive color of switch when it is off '#ddd' string
onSyncPress callback when switch is clicked () => null func
onAsyncPress has a callback with result of async (value, callback) => {callback(true)} func

Notice

  • You'd better not use onSyncPress and onAsyncPress together or else, only onSyncPress will be invoked.

  • value is used with bidirectional binding which could be redux, state and so on.
    In onAsyncPress, you should write like following (with state):

     <Switch
       value={this.state.value}
       onAsyncPress={(callback) => {
         callback(false or true, value => this.setState({value}))
      }}
     />

    value => this.setState({value}) will only be invoked when result is true.

License

MIT

More Repositories

1

react-native-gank

made for gank.io
JavaScript
685
star
2

mdcc-client

a react-native client for mdcc
JavaScript
296
star
3

react-native-intent-launcher

call native function "startActivity" in react-native
JavaScript
77
star
4

react-native-imagefooter-listview

一个具有可以伸缩高度和顶部内容顶部View以及中部标题的ListView
JavaScript
30
star
5

react-native-navigationbar

a navigationBar provided for iOS/Android
JavaScript
20
star
6

react-native-segment-tab

segment-tab looks like ios component
JavaScript
14
star
7

react-native-collapsable-view

a expandable and collapsable view that can be controlled with a handler
JavaScript
11
star
8

VerificationCode

随机生成多种方式验证码的实现
Java
11
star
9

adbwifi

一款可以用来无线真机调试的shell脚本
Shell
4
star
10

SqlCurriculumDesign

一个数据库课设的小app
Java
4
star
11

Blogger

为系列开发周报提供的Demo演示
Objective-C
4
star
12

SwipeRefreshwithLoadmore

给官方的下拉刷新控件添加触底加载功能。。。更应该说给触底加载的listview添加下拉刷新功能(其实也就是二者的组合)
Java
3
star
13

react-native-taobao-detail

a view looks like detail page of taobao mobile app
JavaScript
3
star
14

react-native-check-camera

to check whether camera-permission is denied
Objective-C
3
star
15

react-native-rent-me

balabala, the project info is a secret Y(^_^)Y
JavaScript
3
star
16

TodoList

a todo-list by issues on github
3
star
17

debounce-decorator-pro

a decorator for debounce function
JavaScript
2
star
18

React-Gank

rewrite http://gank.io with React.js
JavaScript
2
star
19

react-native-bga-badge-view

react-native wrapper component for BGABadgeView
Java
2
star
20

Coding-Interview-Guide

一起来撸 左神 的《程序源代码面试指南》这本书吧
Java
1
star
21

react-native-project

my graduation project
JavaScript
1
star
22

react-native-starter

A pretty initial project to start react-native with mobx, react-navigation
JavaScript
1
star
23

Redux-Demo

用Redux做的一个小Demo....only for practice
JavaScript
1
star
24

bot

a script based on wechaty
TypeScript
1
star
25

ImageCache

picture used in github
1
star
26

diary-rn

react-native app for "小记"
1
star
27

Pressure-test-for-MySql

由java实现的一个多线程对Mysql数据库测试
Java
1
star
28

progressBar-progressDialog

关于progressBar和progressDialog的两个demo
Java
1
star
29

Tortoies

基于自定义控件的一个小动画
Java
1
star