Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react native modal close when click outside

<Modal transparent={true} visible={alert} animationType='slide' onRequestClose={() => setalert(false)}>
	<TouchableOpacity activeOpacity={1} style={Styles.center} onPressOut={() => setalert(false)}>
		<TouchableWithoutFeedback>
            {/* Somethings */}
		</TouchableWithoutFeedback>
	</TouchableOpacity>
</Modal >

{/*TouchableOpacity close the modal when click and the TouchableWithoutFeedback block the touch inside the rectangle*/}
{/*Code take from: https://stackoverflow.com/questions/40483034/close-react-native-modal-by-clicking-on-overlay*/}
Comment

Modal dismiss react native by click outside

// You need one touchableOpacity for clicking outside and another touchableOpacity for actual modal that 
// will do nothing onPress.

import React, { Component } from 'react'
import { View, StyleSheet, TouchableOpacity, Modal} from 'react-native';

export class Modal extends Component {
    constructor(props){
        this.state = { modalVisible : true}
    }
    render() {
        return (
            <View>
                <Modal
                    animationType="slide"
                    transparent={true}
                    visible={this.state.modalVisible}
                    onRequestClose={() => { this.setState({modalVisible: false})
                    }}
                  >
                    <TouchableOpacity style={styles.modalContainer} onPress={() => { this.setState({ modalVisible : false})}}>
                        <TouchableOpacity style={styles.modal} onPress={() => console.log('do nothing')} activeOpacity={1} >
                            Modal Content...
                        </TouchableOpacity>
                    </TouchableOpacity>
                </Modal>
            </View>
        )
    }
}


const styles = StyleSheet.create({
    modalContainer: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center',
    },
    modal: {
      width: 155,
      height: 300
    },
});

export default Modal;
Comment

PREVIOUS NEXT
Code Example
Javascript :: date get full year 
Javascript :: run function then empty it javascript 
Javascript :: javascript wait for element 
Javascript :: vue js cdn 
Javascript :: how to find all elements starting with class jquery 
Javascript :: javascript queryselector 
Javascript :: download images from http link in react 
Javascript :: dynamodb get all items nodejs 
Javascript :: javascript get last object in foreach loop 
Javascript :: javascript execute function by string name 
Javascript :: two array in one js 
Javascript :: starting express server 
Javascript :: window.addeventlistener 
Javascript :: If statement discord js 
Javascript :: react dont render component until loaded 
Javascript :: repeat an element in array in js 
Javascript :: js convert string array to number array 
Javascript :: regex js pattern tags 
Javascript :: youtube set speed command 
Javascript :: array every javascript 
Javascript :: async await javascript stack overflow 
Javascript :: log odd numbers js 
Javascript :: how to code print in javascript 
Javascript :: create fooer on print page with jquery 
Javascript :: how to send axios delete to the backend reactjs 
Javascript :: how to convert jsonobject to string in java 
Javascript :: js increment and decrement function for cart 
Javascript :: how to make an array in javascript 
Javascript :: add one file to another in ejs 
Javascript :: http node 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =