I am working on a todo list that can upload, delete and edit the uploaded thing to do on react native. When the edit button is pressed a modal appears in form of a pop up, my goal to make that when it is tapped in the surroundings of the modal(outside the modal) the modal closes. I have been trying to make that work and non of the ways I have tried have worked. I was thinking in using TouchableWithputFeedback for this but the way I made it didnt work. How can this goal be achieved?
app.js
<FlatList
keyExtractor={(item, index) => item.key}
data={ todos }
renderItem={({ item }) => <TodoItem title={item.value} pressHandler={pressHandler.bind(this, item.key)} onPressModal={() => {setAddMode(true)}}/> }
/>
<EditModal visible={addMode} onCancel={() => {setAddMode(!addMode)}}></EditModal>
TodoItem.js
<View style={styles.items}>
<View style={styles.itemContainer}>
<Text style={styles.itemText}>{props.title}</Text>
<View style={styles.btnContainer}>
<Buttons onPress={props.pressHandler} title="Delete" style={styles.itemBtn}></Buttons>
<Buttons title="Edit" style={styles.editBtn} onPress={props.onPressModal}></Buttons>
</View>
</View>
</View>
EditModal.js (I tried using onCancel on the touchablewithoutfeedback but it didnt work, the onCancel that is on the button does work by some reason)
import React from 'react';
import { Modal, StyleSheet, View, TextInput, TouchableWithoutFeedback} from 'react-native';
import Buttons from '../components/Buttons';
const EditModal = props => {
return (
<TouchableWithoutFeedback onPress={props.onCancel}>
<View style={styles.center}>
<Modal visible={props.visible} animationType="slide" transparent={true}>
<View style={styles.editModal}>
<TextInput style={styles.modalTxt}/>
<Buttons title="Edit" style={styles.modalBtn} onPress={props.onCancel}></Buttons>
</View>
</Modal>
</View>
</TouchableWithoutFeedback>
);
};
const styles = StyleSheet.create({
center: {
display: 'flex',
position: 'relative',
alignItems: 'center',
justifyContent: 'center',
},
modalTxt: {
borderWidth: 1,
borderColor: '#FF6666',
paddingVertical: 10,
padding: 5,
borderRadius: 6,
},
modalBtn: {
borderWidth: 1,
backgroundColor: '#FF6666',
borderColor: '#FF6666',
paddingVertical: 10,
padding: 5,
marginTop: 10,
borderRadius: 6,
},
editModal: {
top: '40%',
width: '80%',
height: '20%',
backgroundColor: "white",
borderRadius: 20,
padding: 35,
alignSelf: "center",
justifyContent: 'center',
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.30,
shadowRadius: 4,
elevation: 5
},
});
export default EditModal;