Are there some ways in react-native to create a switcher with this exact design?
I'm using this React Native Switch, it works perfect, but I need plus text 'on' and 'off', maybe custom component? https://reactnative.dev/docs/switch
Thank you!
Are there some ways in react-native to create a switcher with this exact design?
I'm using this React Native Switch, it works perfect, but I need plus text 'on' and 'off', maybe custom component? https://reactnative.dev/docs/switch
Thank you!
You could create your own custom component with React Native. Just Inherit it and Create Own component like as https://github.com/arshigtx/react-native-custom-switch create a component copy inner src fix issues then make it your own. Please start the project.
----- Edited ------
import React, { useState } from "react";
import { View, Switch, StyleSheet,Text } from "react-native";
const App = () => {
const [isEnabled, setIsEnabled] = useState(false);
const toggleSwitch = () => setIsEnabled(previousState => !previousState);
return (
<View style={styles.container}>
<View>
{
isEnabled ? <Text style={{position: 'absolute', color: 'white', top: 3, left: 2, zIndex: 5, fontSize: 11}} >On</Text> : <Text style={{position: 'absolute', color: 'white', top: 3, left: 20, zIndex: 5, fontSize: 11}}>Off</Text>
}
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={isEnabled ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isEnabled}
/>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
}
});
export default App;