How to create a Toggle switch in react-native using Material Design library ? Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms.Approach: In this article, we will see how to create a toggle switch in react-native using material design. We will use react-native-paper library material design to create it. In this project, whenever the switch will be toggled, an alert message will appear that will show the status of the switch.Below is the step by step implementation:Step 1: Create a project in react-native using the following command:npx react-native init DemoProjectStep 2: Install react-native paper using the following command:npm install react-native-paperStep 3: Create a components folder inside your project. Inside the components folder create a file ToggleSwitch.jsProject Structure: It will look like this.Example: Write down the code in respective files. In ToggleSwitch.js , we will import Switch Component from 'react-native-paper' library . ToggleSwitch.js 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' } }) Now import this file in your App.js file App.js import React from 'react'; import type { Node } from 'react'; import { View } from 'react-native'; import ToggleSwitchExample from './components/ToggleSwitch'; const App: () => Node = () => { return ( <View> <ToggleSwitchExample /> </View> ); }; export default App; Step to run the application: Run the application using the following command:npx react-native run-androidOutput: Create Quiz Comment S samiksharanjan Follow 0 Improve S samiksharanjan Follow 0 Improve Article Tags : React Native Geeks-Premier-League-2022 React-Native Explore React Native BasicsIntroduction to React Native4 min readSteps to create first React Native App3 min readHow React Native works5 min readWhat is a bridge in React Native ?7 min readHow React Native is different from ReactJS ?4 min readReact Native Debugging4 min readReact Native ComponentsHow to import components in React Native ?5 min readReact Native ListView Component4 min readReact Native ScrollView Component8 min readReact Native Tab Navigation Component3 min readReact Native Drawer Navigation Component3 min readReact Native ActivityIndicator Component2 min readDumb Components in React Native5 min readWhat is the TouchableHighlight in react native ?4 min readReact Native FlatList Component4 min readReact Native AsyncStorage Component5 min readReact Native Button Component6 min readReact Native UI ElementsHow to style React Native Application ?5 min readHow to create a basic button in React Native ?5 min readReact Native Animated Fade In Fade Out Effect8 min readHow to create custom FAB(Floating Action Button) in React Native?7 min readHow to add a Progress Bar in react-native using react-native-paper library ?10 min readHow to create Avatar in react-native ?6 min readReact Native APIReact Native Switch API6 min readReact Native Alert API6 min readReact Native QuestionsFind what caused Possible unhandled promise rejection in React Native ?5 min readAxios in React Native8 min readHow to create a table in react-native ?2 min readHow to fetch data from a local JSON file in React Native ?3 min readHow to center a View component on screen ?3 min readHow to Add Icons at the Bottom of Tab Navigation in React Native ?3 min readHow to add SearchBar in React Native ?13 min readHow to set Background Image in react-native ?5 min readHow to pass value between Screens in React Native ?6 min readHow to make a Post request from frontend in react-native ?9 min readHow to add GIFs in react-native ?2 min readHow to Implement Form Validation in React Native ?3 min readHow many threads run in a React Native app ?3 min readHow to add Table in React Native ?2 min readHow to add a Menu in react-native using Material Design ?9 min readWhat are props in React Native ?5 min readHow to Implement Radio Button In React Native ?10 min readHow to check the version of React native ?2 min readHow to perform logging in React Native ?4 min readHow to Upload and Preview an Image in React Native ?4 min readHow to Add Phone Number Input in React Native ?3 min readHow to Get Window Width and Height In React Native ?5 min readHow to check Platform and Device Details in React Native ?3 min readReact Native ProjectsTop React Native Apps to Build in 20259 min readHow to Create ToDo App using React Native ?11 min readHow to Create Calendar App in React Native ?7 min readHow to Create a Basic Notes App using React Native?14 min readHow to Generate Random Numbers in React Native ?7 min readBuild a Calculator using React Native10 min readCreate a Task Manager App using React-Native12 min readHow to Create Emoji Picker in React Native ?3 min readCreate a Stop Watch using React Native10 min readCreate an OTP Generator and Validator App using React-Native11 min readCreate a Rock Paper Scissors Game using React-Native10 min readCreate a Number Guessing App using React-Native10 min readCreate a BMI Calculator App using React-Native4 min readCreate a GPA Calculator using React Native15+ min readCreate a Password Manager using React-Native15+ min readCreate Jokes Generator App using React-Native8 min readBuild a Dictionary App Using React Native15+ min readCreate a Blog App using React-Native15+ min readCreate a Text Editor App using React-Native3 min readCreate a Password Validator using React-Native11 min readCreate a Currency Converter using React-Native14 min read Like