Last Updated on : 2024-06-05 03:14:34download
SwitchButton
component can show the task status: whether the task is enabled or disabled.
Note: for more information, see Demo.
import React from 'react';
import { View } from 'react-native';
import { SwitchButton } from 'tuya-panel-kit';
export default class SwitchButtonDemo extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
value: true;
}
}
render() {
return (
<View style={styles.wrApper}>
<SwitchButton
value={this.state.value}
onValueChange={value => { this.setState({ value }); }}
/>
</View>
)
}
}
import React from "react";
import { View } from "react-native";
import { SwitchButton } from "tuya-panel-kit";
const SwitchButtonDemo = () => (
<View style={styles.wrApper}>
<SwitchButton
defaultValue={true}
onValueChange={(value) => console.log(value)}
/>
</View>
);
Specify the style of the container that wraps the SwitchButton.
Type | Required |
---|---|
ViewPropTypes.style | No |
Specify the style of the icon used for dragging in the switch.
Type | Required |
---|---|
ViewPropTypes.style | No |
The currently selected value. After this property is set, it is a controlled component.
Type | Required |
---|---|
bool |
No |
The value selected by default.
Type | Required | Default value |
---|---|---|
bool |
No | true |
Whether to use Native Driver.
Type | Required | Default value |
---|---|---|
bool |
No | true |
Set the size of the development component:
width
: width.height
: height.activeSize
: the size of the sliding button.margin
: the margin of the sliding button from the nearest border.Type | Required | Default value |
---|---|---|
Object |
No | { width: 50, height: 28, activeSize: 26, margin: 1 } |
Set the background color when the value
of the SwitchButton is false
.
Type | Required | Default value |
---|---|---|
Color | No | transparent |
Set the color when the value
of the SwitchButton is true
.
Type | Required | Default value |
---|---|---|
Color | No | #44DB5E |
Set the color of the sliding button when the value
of the SwitchButton is false
.
Type | Required | Default value |
---|---|---|
Color | No | #e5e5e5 |
Set the color of the sliding button when the value
of the SwitchButton is true
. It is the value of thumbTintColor
if it is not set.
Type | Required | Default value |
---|---|---|
Color | No | None |
Set the color of the border when the value
of the sliding button is false
.
Note: when the
value
of the SwitchButton istrue
, the border color is equal toonTintColor
.
Type | Required | Default value |
---|---|---|
Color | No | #e5e5e5 |
Whether to disable the SwitchButton.
Type | Required | Default value |
---|---|---|
bool |
No | false |
This callback is executed when the switch combination value is changed.
Type | Required |
---|---|
(value) => void | No |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback