Home

Awesome

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

<img src="http://ww4.sinaimg.cn/large/005zU9b3jw1faioulkg79j30kq10wq3c.jpg" width="340" height="600"/> &nbsp;&nbsp;&nbsp; <img src="http://ww2.sinaimg.cn/large/005zU9b3jw1faioygbedfg30a90iejrd.gif" width="340" height="600"/>

Feature

Install

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

Usage

import Switch from 'react-native-switch-pro'
...
  render() {
    return (
      <View style={styles.container}>
        <Switch onSyncPress={value => {...}}/>
      </View>
    )
  }
...
...
  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

NameDescriptionDefaultType
widthwidth of switch40number
heightheight of switch21number
valuestate of switch which can be used to bidirectional bindingundefinedbool
disabledwhether switch is clickablefalsebool
circleColorActivecolor for circle handler of switch when it is onwhitestring
circleColorInactivecolor for circle handler of switch when it is offwhitestring
stylestyles that will be applied for switch containerundefinedstyle
circleStylestyles that will be applied for the circleundefinedstyle
backgroundActivecolor of switch when it is ongreenstring
backgroundInactivecolor of switch when it is off'#ddd'string
onSyncPresscallback when switch is clicked() => nullfunc
onAsyncPresshas a callback with result of async(value, callback) => {callback(true)}func

Notice

License

MIT