You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

react-native-switch-pro-with-react-17-support

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-switch-pro-with-react-17-support

an universal switcher for andriod and iOS

1.0.6
latest
Source
npm
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

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

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

  • 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

Keywords

switch

FAQs

Package last updated on 09 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts