Switch toggle component for React Native. You can add title, icon, modify component for toggle button.
npm install react-native-toggle-elementThe library has been rewritten with Typescript support in version 2.0.0. This library will work well on both React Native and Expo, please check out the examples folder.
``bash
yarn add react-native-toggle-element
npm install react-native-toggle-element
`
`jsx
import React, { useState } from "react";
import Toggle from "react-native-toggle-element";
const [toggleValue, setToggleValue] = useState(false);
`
`jsx`
`jsx`
onPress={(newState) => setToggleValue(newState)}
leftTitle="On"
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
leftTitle="Right"
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
leftTitle="Left"
rightTitle="Right"
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
leftComponent={
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
rightComponent={
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
disabled
leftComponent={
}
rightComponent={
}
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
thumbActiveComponent={
}
thumbInActiveComponent={
}
trackBar={{
activeBackgroundColor: "#9ee3fb",
inActiveBackgroundColor: "#3c4145",
borderActiveColor: "#86c3d7",
borderInActiveColor: "#1c1c1c",
borderWidth: 5,
width: 100,
}}
/>
`jsx`
value={toggleValue}
onPress={(newState) => setToggleValue(newState)}
leftTitle="Left"
rightTitle="Right"
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
leftTitle="Left"
rightTitle="Right"
trackBar={{
width: 200,
height: 50,
radius: 25,
}}
/>
TrackBarStyle will override Border active color & Border inactive color
`jsx`
onPress={(newState) => setToggleValue(newState)}
trackBarStyle={{
borderColor: "green",
}}
trackBar={{
borderWidth: 2,
}}
/>
`jsx`
onPress={(newState) => setToggleValue(newState)}
leftTitle="Left"
rightTitle="Right"
thumbButton={{
width: 60,
height: 60,
radius: 30,
}}
/>
`jsx`
disabledTitleStyle={{ color: "red" }}
disabledStyle={{ backgroundColor: "gray", opacity: 0.3 }}
value={toggleValue}
onPress={(newState) => setToggleValue(newState)}
leftTitle="Left"
rightTitle="Right"
/>
- containerStyle
- disabled
- disabledStyle
- disabledTitleStyle
- leftComponent
- leftTitle
- rightComponent
- rightTitle
- thumbActiveComponent
- thumbInActiveComponent
- thumbStyle
- thumbButton
- trackBar
- trackBarStyle
- animationDuration
| Type | Default |
| -------------------------- | :-----: |
| React element or component | none |
containerStyle style for main container
| Type | Default |
| ----- | :-----: |
| style | none |
disabled disable the Toggle Button component (optional)
| Type | Default |
| ------- | :-----: |
| boolean | false |
disabledStyle styling for Toggle Button Component for disabled (optional)
| Type | Default |
| ------------------- | :-----: |
| View style (object) | none |
disabledTitleStyle styling for leftTitle & right Title(optional) when Toggle Button set with status is disabled(optional). If you want to set disable style for Active & Inactive you should use custom left component or custom right component
| Type | Default |
| -------------------- | :-----: |
| Text style (object)) | none |
leftComponent define your left component here
| Type | Default |
| -------------------------- | :-----: |
| React element or component | none |
leftTitle button left title (optional)
| Type | Default |
| ------ | :-----: |
| string | none |
rightComponent define your right component here (optional)
| Type | Default |
| -------------------------- | :-----: |
| React element or component | none |
rightTitle button right title (optional)
| Type | Default |
| ------ | :-----: |
| string | none |
thumbActiveComponent define your thumb button component when status is active (optional)
| Type | Default |
| -------------------------- | :-----: |
| React element or component | none |
thumbInActiveComponent define your thumb button component when status is inactive (optional)
| Type | Default |
| -------------------------- | :-----: |
| React element or component | none |
thumbStyle thumb button style (optional). Styling will override the value from thumbButton props
| Type | Default |
| ------------------- | :-----: |
| View style (object) | none |
thumbButton define to change size and radius and color depend on active / inactive status (optional)
| Type | Default |
| ----------------------- | :-----: |
| borderWidth | 0 |
| width | 50 |
| height | 50 |
| radius | 25 |
| activeBackgroundColor | #fde2e2 |
| inActiveBackgroundColor | #ffb6b6 |
trackBar define to change size and radius and color depend on active / inactive status (optional)
| Type | Default |
| ----------------------- | :---------: |
| borderWidth | 0 |
| width | 50 |
| height | 50 |
| radius | 25 |
| activeBackgroundColor | #fde2e2 |
| inActiveBackgroundColor | #ffb6b6 |
| borderActiveColor | transparent |
| borderInActiveColor | transparent |
trackBarStyle trackbar style (optional). Styling will override the value from trackBar props
| Type | Default |
| ------------------- | :-----: |
| View style (object) | none |
animationDuration` duration of the thumb button animation (optional).
| Type | Default |
| ------ | :-----: |
| number | 350 |