Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

react-native-switch-pro

versiondownloadsdownloads
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 peformance 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
importSwitchfrom'react-native-switch-pro'
...
render(){return(<Viewstyle={styles.container}><SwitchonSyncPress={value=>{...}}/></View>)}
...
  • Async
...
render(){return(<Viewstyle={styles.container}><SwitchonAsyncPress={(callback)=>{Youcancallyourasyncmoduleandjustinvokecallback(true)whensucceed,callback(false)whenfail.}}/></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
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

  • 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):

    <Switchvalue={this.state.value}onAsyncPress={(callback)=>{callback(falseortrue,value=>this.setState({value}))}}/>

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

License

MIT

About

react-native-switch-pro with UNSAFE methods renamed

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages