React Native Modal component is used to display content on existing View. This is similar to Android Dialog Fragment.
Syntax
|
Example
import React, {Component} from 'react'; import {Button, Text, View, Modal, StyleSheet} from 'react-native';
export default class ModalTModalExample extends Component { state = { isModalVisible: true, };
toggleModal = () => { this.setState({isModalVisible: !this.state.isModalVisible}); };
render() { return ( <View style={{flex: 1}}> <View style={styles.header}> <Text>Modal Component</Text> </View> <View style={styles.body}> <Button title="Show modal" onPress={this.toggleModal} /> <Modal animationType={'slide'} transparent={false} visible={this.state.isModalVisible} onRequestClose={() => { console.log('Modal has been closed.'); }}> {/*All views of Modal*/} {/*Animation can be slide, slide, none*/} <View style={styles.modal}> <Text style={styles.text}>Modal is open!</Text> <Button title="Click To Close Modal" onPress={() => { this.setState({isModalVisible: !this.state.isModalVisible}); }} /> </View> </Modal> </View> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#FAFAFA', marginTop: 30, }, modal: { flex: 1, alignItems: 'center', backgroundColor: 'yellow', padding: 100, }, text: { color: '#3f2949', marginTop: 10, }, header: { alignItems: 'center', padding: 10, backgroundColor: 'cyan', }, body: { backgroundColor: 'grey', padding: 16, flex: 1, }, });
|
Output
Ruby program to add two integer numbers
how to create an array with Array.[](*args) in Ruby ?
What are the various Ruby runtimes, and how are they different?
Ruby program to check whether the given number is prime or not
Ruby program to reverse a string
Ruby program to check whether the given number is palindrome
Ruby program to print Fibonacci series
How to Replace array elements in Ruby?
Ruby program to print an array
Ruby program to check whether the given number is Armstrong
Program to Print Triangle of Numbers in Ruby
How to add/remove elements to Array in Ruby?
How to shuffle an array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
Ruby program to generate random numbers
Ruby program to Calculate the factorial of given number
What are #method_missing and #send? Why are they useful?
How to Sort Array in Ruby?
How to get index of array element in Ruby
How to Get Input with Gets in Ruby
How to create two dimensional array in ruby?