I have add comment button when user clicks on add comment button he should be able to add and save comment. For comment save I have used Modal. Now I want to close Modal when user clicks outside Modal how can I do this is React Native ?
I am referring this -> Close react native modal by clicking on overlay? but the solution is not working in my case.
Note: I have added button to close modal but I want to close the modal by clicking outside it.
Code:
<View>
<Modal
animationType="slide"
transparent={true}
visible={this.state.modalVisible}
onRequestClose={() => {this.setModalVisible(false)}}>
<TouchableOpacity
activeOpacity={1}
onPressOut={() => {this.setModalVisible(true)}}
>
<ScrollView
directionalLockEnabled={true}
contentContainerStyle={styles.scrollModal}
>
<TouchableWithoutFeedback>
<View style={styles.commentModal}>
<View style={{marginLeft: 20, marginRight: 20}}>
<Text style={styles.addCommentModal}>Add a Comment</Text>
<View style={styles.textInputModal}>
<TextInput
editable = {true}
maxLength = {40}
multiline = {true}
onChangeText={(text) => this.setState({text})}
value={this.state.comment_text}
onChangeText={(text) => this.setState({comment_text: text})}
style={{borderRadius: 1}}
/>
</View>
<View style={styles.modalBtnContainer}>
<TouchableOpacity onPress={() => this.addComment(this.state.comment_text, logged_in_user.id, marketingPlanId)}>
<Text style={styles.saveCommentModal}>Save Comment</Text>
</TouchableOpacity>
</View>
<View style={styles.modalBtnContainer}>
<TouchableOpacity onPress={() => this.setModalVisible(false)}>
<Text style={styles.closeCommentModal}>Close</Text>
</TouchableOpacity>
</View>
</View>
</View>
</TouchableWithoutFeedback>
</ScrollView>
</TouchableOpacity>
</Modal>
</View>
CSS:
commentModal: {
position: 'absolute',
bottom: 0,
backgroundColor: '#fff',
height: height/2,
width: width
},
addCommentModal: {
fontSize: 18,
color: '#333',
marginTop: 20,
fontFamily: 'bold',
fontWeight: '500'
},