Close react native modal by clicking on overlay?

前端 未结 13 677
梦如初夏
梦如初夏 2020-12-23 14:27

Is it possible to close react native modal by clicking on overlay when transparent option is true? Documentation doesn\'t provide anything about it

13条回答
  •  太阳男子
    2020-12-23 14:40

    Here is my solution,

    import React from "react";
    import {Modal, StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View} from "react-native";
    
    // make sure the styles props is passed to the model and contains modalContainer, as well as the childrenContainer style objects.
    
    export default class DismissibleModal extends React.Component {
        render() {
            return (
                 {this.props.dismiss()}}>
                   {this.props.dismiss()}}>
                        
                            
                                
                                    {this.props.children}
                                
                            
                        
                  
            
            )
        }
    
    }
    
    
    
    const Styles = StyleSheet.create({
        modal: {
            flex: 1,
            backgroundColor: 'transparent',
            flexDirection: 'row',
            justifyContent: 'center',
            alignItems: 'center'
        },
        modalView: {
            backgroundColor: "white",
            borderRadius: 10,
            padding: 20,
            paddingTop: 20,
            alignItems: "center",
            shadowColor: "#000",
            shadowOffset: {
                width: 0,
                height: 9,
            },
            shadowOpacity: 0.50,
            shadowRadius: 12.35,
    
            elevation: 19,
      },
    });
    

提交回复
热议问题