Skip to main content

React Native Modal Popup Tutorial

React Native Modal Popup Tutorial

Hi dev,

Today, I will learn you how to create modal popup in react native. You can easily create modal in react native. First i will import namespace Modal, after I will make modal using modalVisible method in react native.

Here, I will give you full example for simply display modal using react native as bellow.

Step 1 - Create project

In the first step Run the following command for create project.


expo init Modal
Step 2 - App.js

In this step, You will open App.js file and put the code.


import React, { Component } from "react";
import { Alert,Modal,StyleSheet,Text,TouchableHighlight,View ,Header } from "react-native";

class App extends Component {
state = {
modalVisible: false
};

setModalVisible = (visible) => {
this.setState({ modalVisible: visible });
}

render() {
const { modalVisible } = this.state;
return (
<View style={styles.view}>
<Text style={styles.header}>React Native Modal Popup Example itwebtuts.com</Text>
<Modal
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert("Modal has been closed.");
}}
>
<View style={styles.view}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Hii Friends!</Text>

<TouchableHighlight
style={{ ...styles.openButton, backgroundColor: "#2196F3" }}
onPress={() => {
this.setModalVisible(!modalVisible);
}}
>
<Text style={styles.textStyle}>Hide Modal</Text>
</TouchableHighlight>
</View>
</View>
</Modal>

<TouchableHighlight
style={styles.openButton}
onPress={() => {
this.setModalVisible(true);
}}
>
<Text style={styles.textStyle}>Show Modal</Text>
</TouchableHighlight>
</View>
);
}
}

const styles = StyleSheet.create({
view: {
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 0
},
modalView: {
margin: 30,
backgroundColor: "white",
borderRadius: 20,
padding: 35,
alignItems: "center",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 5
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5
},
openButton: {
backgroundColor: "#115454",
borderRadius: 5,
padding: 15,
elevation: 2
},
textStyle: {
color: "white",
textAlign: "center",
},
modalText: {
marginBottom: 15,
},
header:{
textAlign: 'center',
fontSize: 20,
marginBottom: 50,
}
});

export default App;
Step 3 - Run project

In the last step run your project using bellow command.


npm start
It will help you..

Comments

Popular posts from this blog

Laravel 6 validation required if another field is empty

Hii guys, In this artical, i will give you example of laravel 6 in validation required if another field is empty. We know laravel provide several in-built laravel 6 validation required_without . If you need to add validation rules like required if other field is empty in laravel then you can do it using required_without. I am going to explain you, If you can not enter test (field) value at that time test1 (field) is required. So at that time you can add validation required_without. So, you can use this way: "test1" =>"required_without:test" Example: public function store(Request $request) { $request->validate([ "test" =>"required", "test1" =>"required_without:test" ]); dd("Done!"); } If return validation error otherwise show Done!. It will help you...

Laravel IP Address Using Get Location Example

Hi Dev, Today,I will learn you how to get location useing ip address in laravel. we will show example of laravel ip address using get location. you can easy to get location useing ip address in laravel.In this example, I will useing stevebauman/location packege get location useing ip address in laravel. Many time you will need to get visitor's details for security, spam prevention etc. It's very easy to get visitor ip address and their location in PHP Laravel. Step 1: Install stevebauman/location Now, We will install stevebauman/location package using below command.Require this package with composer. It is recommended to only require the package for development. composer require stevebauman/location Step 2: Add providers and aliases In this step,We will add below providers and aliases in the "config/app.php" file. config/app.php 'providers' => [ .... Stevebauman\Location\LocationServiceProvider::class, ], 'aliases' => [ .... 'Loca...

React Native Flexbox Tutorial With Example

Hi Dev, Today, I will learn you how to create flexbox in react native. You can easily create flexbox in react native. First i will import namespace View , after I will make flexbox using View tag in react native. Here, I will give you full example for simply display flexbox using react native as bellow. Step 1 - Create project In the first step Run the following command for create project. expo init flexbox Step 2 - App.js In this step, You will open App.js file and put the code. import React, { Component } from 'react' import { View, StyleSheet } from 'react-native' const Home = (props) => { return ( <View style = {styles.container}> <View style = {styles.redbox} /> <View style = {styles.greenbox} /> <View style = {styles.corolbox} /> <View style = {styles.purplebox} /> </View> ) } export default Home const styles = StyleSheet.create ({ container: { flexDirection:...