-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoalItem.js
More file actions
92 lines (84 loc) · 2.22 KB
/
GoalItem.js
File metadata and controls
92 lines (84 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, { useState } from "react";
import { View, Text, TouchableOpacity, StyleSheet, Modal, Button } from "react-native";
const GoalItem = ({ goal, onDelete }) => {
const [isConfirmVisible, setIsConfirmVisible] = useState(false);
const handleDelete = () => {
setIsConfirmVisible(true);
};
const handleConfirmDelete = () => {
setIsConfirmVisible(false);
onDelete();
};
const handleCancelDelete = () => {
setIsConfirmVisible(false);
};
return (
<View style={styles.listItemContainer}>
<Text style={styles.listItem}>{goal}</Text>
<TouchableOpacity onPress={handleDelete} style={styles.deleteButton}>
<Text style={styles.deleteButtonText}>X</Text>
</TouchableOpacity>
{/* Modal de confirmation */}
<Modal
animationType="slide"
transparent={true}
visible={isConfirmVisible}
onRequestClose={handleCancelDelete}
>
<View style={styles.modalContainer}>
<View style={styles.modalContent}>
<Text style={styles.modalText}>Êtes-vous sûr de vouloir supprimer cet objectif ?</Text>
<View style={styles.buttonContainer}>
<Button title="Oui" onPress={handleConfirmDelete} />
<Button title="Non" onPress={handleCancelDelete} color="red" />
</View>
</View>
</View>
</Modal>
</View>
);
};
const styles = StyleSheet.create({
listItemContainer: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
marginBottom: 10,
},
listItem: {
fontSize: 18,
},
deleteButton: {
backgroundColor: "red",
borderRadius: 5,
padding: 5,
},
deleteButtonText: {
color: "white",
fontWeight: "bold",
},
modalContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "rgba(0, 0, 0, 0.5)",
},
modalContent: {
backgroundColor: "white",
padding: 20,
borderRadius: 10,
alignItems: "center",
elevation: 5,
},
modalText: {
marginBottom: 20,
fontSize: 18,
textAlign: "center",
},
buttonContainer: {
flexDirection: "row",
justifyContent: "space-around",
width: "100%",
},
});
export default GoalItem;