Finally I got the On off inside switch .......

install

npm install --save react-native-switch

    import { Switch } from 'react-native-switch';

<Switch
value={true}
onValueChange={(val) => console.log(val)}
disabled={false}
activeText={'On'}
inActiveText={'Off'}
backgroundActive={'green'}
backgroundInactive={'gray'}
circleActiveColor={'#30a566'}
circleInActiveColor={'#000000'}/>

Refer this link... https://github.com/shahen94/react-native-switch

Answer from Lavaraju on Stack Overflow
๐ŸŒ
GitHub
github.com โ€บ prsn โ€บ react-native-toggle-switch
GitHub - prsn/react-native-toggle-switch: Toggle switch with label and swipe behaviour ยท GitHub
import ToggleSwitch from 'rn-toggle-switch' class Demo extends ... { ... render() { return ( ... <ToggleSwitch text={{on: 'PRESENT', off: 'ABSENT', activeTextColor: 'white', inactiveTextColor: '#B7B8BA'}} textStyle={{fontWeight: 'bold'}} color={{ indicator: 'white', active: 'rgba(32, 193, 173, 1)', inactive: 'rgba( 247, 247, 247, 1)', activeBorder: '#41B4A4', inactiveBorder: '#E9E9E9'}} active={true} disabled={false} width={80} radius={25} onValueChange={(val) => { /* your handler function...
Starred by 29 users
Forked by 19 users
Languages ย  JavaScript 64.1% | Objective-C 18.9% | Python 10.1% | Java 6.9%
๐ŸŒ
React Native
reactnative.dev โ€บ docs โ€บ switch
Switch ยท React Native
1 week ago - The value of the switch. If true the switch will be turned on.
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ toggle-switch-react-native
toggle-switch-react-native - npm
Toggle Switch Component for react native, it works on Android, iOS and Web (react-native-web).
      ยป npm install toggle-switch-react-native
    
Published ย  Nov 09, 2021
Version ย  3.3.0
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ react native โ€บ how-to-create-a-toggle-switch-in-react-native-using-material-design-library
How to create a Toggle switch in react-native using Material Design library ? - GeeksforGeeks
July 29, 2024 - In ToggleSwitch.js , we will import Switch Component from 'react-native-paper' library . ... import React, {useState, useEffect} from 'react'; import { Text, View , StyleSheet, Alert} from 'react-native'; import { Switch} from 'react-native-paper' ; const ToggleSwitchExample = () =>{ const [switchOn, setSwitchOn] = useState(false) return( <View style ={styles.container}> <Text>Toggle Switch</Text> <Switch value={switchOn} onValueChange={() => { setSwitchOn(!switchOn) Alert.alert("Switch on : " + !switchOn)} }/> </View> ) } export default ToggleSwitchExample ; const styles = StyleSheet.create({ container:{ padding:45, flexDirection:'row', justifyContent:'space-around' } })
Top answer
1 of 2
11

Finally I got the On off inside switch .......

install

npm install --save react-native-switch

    import { Switch } from 'react-native-switch';

<Switch
value={true}
onValueChange={(val) => console.log(val)}
disabled={false}
activeText={'On'}
inActiveText={'Off'}
backgroundActive={'green'}
backgroundInactive={'gray'}
circleActiveColor={'#30a566'}
circleInActiveColor={'#000000'}/>

Refer this link... https://github.com/shahen94/react-native-switch

2 of 2
4

I would start with something like this and then iterate and polish until it fulfills the requirements and looks good. This isn't a complete solution but should give you some ideas.

    import React from 'react';
    import { LayoutAnimation, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

    const styles = StyleSheet.create({
      container: {
        width: 80,
        height: 30,
        backgroundColor: 'grey',
        flexDirection: 'row',
        overflow: 'visible',
        borderRadius: 15,
        shadowColor: 'black',
        shadowOpacity: 1.0,
        shadowOffset: {
          width: -2,
          height: 2,
        },
      },
      circle: {
        width: 34,
        height: 34,
        borderRadius: 17,
        backgroundColor: 'white',
        marginTop: -2,
        shadowColor: 'black',
        shadowOpacity: 1.0,
        shadowOffset: {
          width: 2,
          height: 2,
        },
      },
      activeContainer: {
        backgroundColor: 'blue',
        flexDirection: 'row-reverse',
      },
      label: {
        alignSelf: 'center',
        backgroundColor: 'transparent',
        paddingHorizontal: 6,
        fontWeight: 'bold',
      },
    });

    class LabeledSwitch extends React.Component {
      constructor(props) {
        super(props);
        this.state = {
          value: props.value,
        };
        this.toggle = this.toggle.bind(this);
      }
      componentWillReceiveProps(nextProps) {
        // update local state.value if props.value changes....
        if (nextProps.value !== this.state.value) {
          this.setState({ value: nextProps.value });
        }
      }
      toggle() {
        // define how we will use LayoutAnimation to give smooth transition between state change
        LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
        const newValue = !this.state.value;
        this.setState({
          value: newValue,
        });

        // fire function if exists
        if (typeof this.props.onValueChange === 'function') {
          this.props.onValueChange(newValue);
        }
      }
      render() {
        const { value } = this.state;

        return (
          <TouchableOpacity onPress={this.toggle}>
            <View style={[
              styles.container,
              value && styles.activeContainer]}
            >
              <View style={styles.circle} />
              <Text style={styles.label}>
                { value ? 'YES' : 'NO' }
              </Text>
            </View>
          </TouchableOpacity>
        );
      }
    }

    LabeledSwitch.propTypes = {
      onValueChange: React.PropTypes.func,
      value: React.PropTypes.bool,
    };

    LabeledSwitch.defaultProps = {
    };

    export default LabeledSwitch;
๐ŸŒ
GitHub
github.com โ€บ mymai91 โ€บ react-native-toggle-element
GitHub - mymai91/react-native-toggle-element: Switch toggle component for React Native. You can add title, icon, modify component for toggle button. ยท GitHub
import React, { useState } from "react"; import Toggle from "react-native-toggle-element"; const [toggleValue, setToggleValue] = useState(false); <Toggle value={toggleValue} onPress={(val) => setToggleValue(val)} /> <Toggle value={toggleValue} onPress={(newState) => setToggleValue(newState)} leftTitle="On" /> <Toggle value={toggleValue} onPress={(newState) => setToggleValue(newState)} leftTitle="Right" /> <Toggle value={toggleValue} onPress={(newState) => setToggleValue(newState)} leftTitle="Left" rightTitle="Right" />
Starred by 178 users
Forked by 20 users
Languages ย  TypeScript 99.7% | JavaScript 0.3%
๐ŸŒ
GitHub
github.com โ€บ nithinpp69 โ€บ react-native-switch-toggles
GitHub - nithinpp69/react-native-switch-toggles: react Native customizable switch component library ยท GitHub
import Switch from 'react-native-switch-toggles'; const [isEnabled, setIsEnabled] = React.useState(false); .... <Switch size={50} value={isEnabled} onChange={(value) => setIsEnabled(value)} renderOffIndicator={() => <Text style={{ fontSize: 16, color: 'white' }}>๐ŸŒš</Text>} renderOnIndicator={() => <Text style={{ fontSize: 16, color: 'white' }}>๐ŸŒ</Text>} /> <Switch size={50} value={isEnabled} onChange={(value) => setIsEnabled(value)} activeTrackColor={"#45D058"} renderOffIndicator={() => <Text style={{ fontSize: 16, color: 'white' }}>OFF</Text>} renderOnIndicator={() => <Text style={{ fontSize: 16, color: 'white' }}>ON</Text>} />
Starred by 18 users
Forked by 3 users
Languages ย  TypeScript 97.3% | JavaScript 2.2% | Shell 0.5%
Find elsewhere
๐ŸŒ
Swmansion
docs.swmansion.com โ€บ react-native-reanimated โ€บ examples โ€บ switch
Switch | React Native Reanimated
1 week ago - const Switch = ({ value, onPress, style, duration = 400, trackColors = { on: '#82cab2', off: '#fa7f7c' }, }) => { const height = useSharedValue(0); const width = useSharedValue(0); const trackAnimatedStyle = useAnimatedStyle(() => { const color = interpolateColor( value.value, [0, 1], [trackColors.off, trackColors.on] ); const colorValue = withTiming(color, { duration }); return { backgroundColor: colorValue, borderRadius: height.value / 2, }; }); const thumbAnimatedStyle = useAnimatedStyle(() => { const moveValue = interpolate( Number(value.value), [0, 1], [0, width.value - height.value] ); c
๐ŸŒ
Techup
techup.co.in โ€บ home โ€บ react-native โ€บ custom toggle switch in react native
Create Custom toggle switch in React Native - Building Digital Solutions
May 18, 2021 - onSelectSwitch : OnSelectSwitch const function triggers after toggle changes. selectionColor : SelectionColor use to set selection color. import React, {useState} from 'react'; import {StyleSheet, Text, View, TouchableOpacity} from 'react-native'; import CustomSwitch from './CustomSwitch'; export default function Dashboard({navigation}) { const onSelectSwitch = index => { alert('Selected index: ' + index); }; return ( <View style={{alignItems: 'center'}}> <Text style={{fontSize: 25, margin: 20, textAlign:'center'}}> React native switch selection button </Text> <View style={{alignItems: 'center
๐ŸŒ
React Native Elements
reactnativeelements.com โ€บ switch
Switch | React Native Elements
Switch represents user's decision of a process and indicates whether a state is on/off. Switch is a controlled component that requires an onValueChange to update the value prop. This renders a boolean value. React native elements provide you with additional theme and color support in the Switch Button.
๐ŸŒ
GitHub
github.com โ€บ aminebenkeroum โ€บ toggle-switch-react-native
GitHub - aminebenkeroum/toggle-switch-react-native: Toggle Switch React Native Component works on both iOS and Android
Toggle Switch Component for react native, it works on Android, iOS and Web (react-native-web).
Starred by 237 users
Forked by 71 users
Languages ย  JavaScript 52.4% | Objective-C 27.8% | Starlark 10.9% | Java 8.9% | JavaScript 52.4% | Objective-C 27.8% | Starlark 10.9% | Java 8.9%
๐ŸŒ
Medium
medium.com โ€บ @amolakapadi โ€บ how-to-build-a-yes-no-switch-toggle-in-react-native-expo-step-by-step-328920fb8e80
How to build a YES / NO switch toggle in React Native (Expo) โ€” Step-by-Step | by Amol kapadi | Medium
December 4, 2025 - In this short tutorial youโ€™ll learn how to create a clean YES / NO toggle using Expo + React Native, center it both vertically and horizontally, show both labels at all times, and highlight the selected option. Includes full code, explanation, accessibility tips, and simple customization ideas. import React, { useState } from "react"; import { View, Text, Switch, StyleSheet } from "react-native"; export default function App() { const [isEnabled, setIsEnabled] = useState(false); return ( <View style={styles.container}> {/* Title Text */} <Text style={styles.title}>Do you agree?</Text> {/* YES / NO + Switch */} <View style={styles.row}> <Text style={[styles.optionText, !isEnabled && styles.activeText]}>NO</Text> <Switch trackColor={{ false: "#c4c4c4", true: "#81b0ff" }} thumbColor={isEnabled ?
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ react native โ€บ react-native-switch-api
React Native Switch API - GeeksforGeeks
February 16, 2026 - - App Component: Wrap the Switch and Text with a View and return that inside the App function to render and place the toggle function and useState inside the App function, also make sure to export the App.
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ javascript โ€บ create a toggle switch in react as a reusable component
Create a Toggle Switch in React as a Reusable Component โ€” SitePoint
November 15, 2024 - Learn how to create an iOS-inspired toggle switch using React components, building a simple demo React App for using this custom toggle switch component.
Top answer
1 of 1
6

Hye finally i made a custom switch, do check out :

Do check out this expo https://snack.expo.dev/@gaurav1995/gnarly-sandwich

Its completely built with react native, no external libraries etc

Do lemme know in case of any doubts :)

import React, { useState, useRef } from 'react';
import {
  Text,
  View,
  StyleSheet,
  Animated,
  TouchableOpacity,
  Easing
} from 'react-native';


export default function App() {

    const positionButton = useRef(new Animated.Value(0)).current;

  const [isOn, setIsOn] = useState(false);

  const startAnimToOff = () => {
    Animated.timing(positionButton,{
      toValue:0,
      duration:500,
      easing:Easing.ease
    }).start()
  };

  const startAnimToOn = () => {
 Animated.timing(positionButton,{
      toValue:1,
      duration:500,
      easing:Easing.ease
    }).start()

  };

  const positionInterPol = positionButton.interpolate({inputRange:[0,1],outputRange:[0,30]})

  const backgroundColorAnim = positionButton.interpolate({inputRange:[0,1],outputRange:["#767577","#81b0ff"]})

  const initialOpacityOn = positionButton.interpolate({inputRange:[0,1],outputRange:[0,1]})

    const initialOpacityOff = positionButton.interpolate({inputRange:[0,1],outputRange:[1,0]})

  const onPress = () => {
    if (isOn) {
      startAnimToOff();
      setIsOn(false);
    } else {
      startAnimToOn();
      setIsOn(true);
    }
  };

  return (
    <View style={styles.container}>
      <TouchableOpacity style={{height:30,width:60}}  activeOpacity={0.9} onPress={onPress} >
      <Animated.View style={[styles.mainStyes,{
        backgroundColor:backgroundColorAnim
      }]} >
        <Animated.Text
          style={[
            styles.eahcStyles,
            {
              opacity: initialOpacityOn,
            },
          ]}>
          ON
        </Animated.Text>
        <Animated.Text
          style={[
            styles.eahcStylesOf,
            {
              opacity: initialOpacityOff,
            },
          ]}>
          OFF
        </Animated.Text>
        <Animated.View style={[styles.basicStyle,{
          transform:[{
            translateX:positionInterPol
          }]
        }]} />
          </Animated.View>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  basicStyle: {
    height: 20,
    width: 20,
    borderRadius: 20,
    backgroundColor: '#FFF',
    marginTop: 5,
    marginLeft: 5,
  },
  eahcStyles: {
    fontSize: 14,
    color: '#f5dd4b',
    position: 'absolute',
    top: 6,
    left: 5,
  },

  eahcStylesOf: {
    fontSize: 14,
    color: '#f4f3f4',
    position: 'absolute',
    top: 6,
    right: 5,
  },
  mainStyes: {
    borderRadius: 30,
    backgroundColor: '#81b0ff',
    height: 30,
    width: 60,
  },

  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});

๐ŸŒ
MageComp
magecomp.com โ€บ home โ€บ react native โ€บ react native | switch
React Native | Switch
February 27, 2025 - The Switch component is a mainstay of the React Native library in React Native and aids in user interaction by performing a toggle action. With this versatile component, users can very smoothly switch between two very distinct states that represent an on/off or true/false condition.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ react native tutorial โ€บ react native switch
React Native Switch - JavaScript Tutorial
October 10, 2024 - <Switch value = {isEnabled } onValueChange={toggleSwitch} /> Code language: HTML, XML (xml) ... import React, { useState } from 'react'; import { StyleSheet, Text, View, Switch } from 'react-native'; const SwitchDemo = () => { const [isEnabled, setIsEnabled] = useState(false); const toggleSwitch = () => setIsEnabled(!isEnabled); return ( <View style={styles.container}> <Text style={styles.text}>{isEnabled ?