Close react native modal by clicking on overlay?

前端 未结 13 656
梦如初夏
梦如初夏 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:54

    Here is my simple implementation:

    <TouchableWithoutFeedback onPress={}> // Code to close your modal goes here
        <View style={styles.background}> // The view to drawn the background
                <View
                    onStartShouldSetResponder={() => true}
                    style={styles.container}
                > // The view to drawn your modal
                // Your content
                </View>
            </Androw>
        </View>
    </TouchableWithoutFeedback>
    

    I use TouchableWithoutFeedback since i do not want to change the background color when clicking on it. I also added onStartShouldSetResponder on the modal view to prevent closing the modal when you click inside the view.

    I am also not using the Modal component because i done it using react-navigation.

    0 讨论(0)
提交回复
热议问题