-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
227 lines (212 loc) · 5.7 KB
/
Copy pathApp.js
File metadata and controls
227 lines (212 loc) · 5.7 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import { useCallback, useEffect, useState } from "react";
import uuid from "react-native-uuid";
import {
FlatList,
Image,
ImageBackground,
Modal,
Pressable,
StyleSheet,
Text,
View,
} from "react-native";
import Product from "./components/Product";
import AddProduct from "./components/AddProduct";
import DissmissKeyboard from "./components/DissmissKeyboard";
import ButtonComponent from "./components/ButtonComponent";
import Header from "./components/Header";
import Colors from "./constants/colors";
import { useFonts } from "expo-font";
import * as SplashScreen from "expo-splash-screen";
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
export default function App() {
// chargement des fonts
const [fontsLoaded] = useFonts({
"Raleway-Bold": require("./assets/fonts/Raleway-Bold.ttf"),
"Raleway-Regular": require("./assets/fonts/Raleway-Regular.ttf"),
});
const [productsList, setProductsList] = useState([]);
const [isModalVisible, setIsModalVisible] = useState(false);
const [isModalAddProduct, setIsModalAddProduct] = useState(false);
useEffect(() => {
console.log('Open modal add product')
async function prepare() {
await SplashScreen.preventAutoHideAsync();
}
prepare();
}, []);
if (!fontsLoaded) {
return null;
} else {
SplashScreen.hideAsync();
}
const onAddProduct = (newProduct) => {
setIsModalAddProduct(false);
if (newProduct.length > 1) {
// plus secure de faire une callback fn dans le setter
setProductsList((currentProductsList) => [
// on récupère les products déjà existant
...currentProductsList,
// on ajoute le nouveau produit
{
id: uuid.v4(),
name: newProduct,
},
]);
} else {
setIsModalVisible(true);
}
console.table(productsList)
};
const onRemoveProduct = (productID) => {
setProductsList((currentProductsList) =>
currentProductsList.filter((product) => product.id !== productID)
);
};
const onAddProductModalBtn = () => {
setIsModalAddProduct(true);
};
return (
<DissmissKeyboard>
<ImageBackground
source={require("./assets/metal-bg.jpg")}
resizeMode="cover"
style={styles.bgImage}
>
<Header />
<View style={styles.container}>
<Modal
visible={isModalVisible}
onRequestClose={() => setIsModalVisible(false)}
animationType="slide"
hardwareAccelerated
transparent
>
<View style={styles.modalContainer}>
<View style={styles.modalContent}>
<View style={styles.modalHeader}>
<Text style={styles.modalHeaderText}>Oups !</Text>
</View>
<View style={styles.modalBody}>
<Image
style={styles.crossIcon}
source={require("./assets/cross.png")}
/>
<Text style={styles.modalBodyText}>
Merci d'indiquer plus d'un seul caractère.
</Text>
</View>
<View style={styles.modalFooter}>
<Pressable
style={styles.modalFooterBtn}
onPress={() => setIsModalVisible(false)}
>
<Text style={styles.modalFooterText}>Ok</Text>
</Pressable>
</View>
</View>
</View>
</Modal>
<ButtonComponent
handleClick={onAddProductModalBtn}
style={styles.addProductBtn}
>
Nouveau Produit
</ButtonComponent>
{isModalAddProduct && (
<AddProduct
onAddProduct={onAddProduct}
isModalAddProduct={isModalAddProduct}
setIsModalAddProduct={setIsModalAddProduct}
/>
)}
<FlatList
data={productsList}
renderItem={({ item }) => (
<Product product={item} onRemoveProduct={onRemoveProduct} />
)}
keyExtractor={(item) => item.id}
/>
</View>
</ImageBackground>
</DissmissKeyboard>
);
}
const styles = StyleSheet.create({
container: {
padding: 40,
paddingTop: 60,
flex: 1,
},
bgImage: {
flex: 1,
},
modalContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "rgba(0, 0, 0, 0.2)",
},
modalContent: {
backgroundColor: Colors.white,
width: "90%",
height: 300,
borderRadius: 15,
alignItems: "center",
},
modalHeader: {
width: "100%",
padding: 16,
alignItems: "center",
borderTopLeftRadius: 15,
borderTopRightRadius: 15,
borderBottomWidth: 1,
borderBottomColor: Colors.lightgrey,
},
modalHeaderText: {
color: Colors.grey,
fontSize: 17,
},
modalBody: {
width: "100%",
flex: 1,
alignItems: "center",
justifyContent: "space-around",
borderBottomLeftRadius: 15,
borderBottomRightRadius: 15,
paddingVertical: 20,
},
modalBodyText: {
fontSize: 17,
},
crossIcon: {
width: 80,
height: 80,
},
modalFooter: {
width: "100%",
},
modalFooterBtn: {
backgroundColor: Colors.lightgreen,
borderBottomLeftRadius: 15,
borderBottomRightRadius: 15,
},
modalFooterText: {
fontSize: 17,
color: Colors.white,
textAlign: "center",
padding: 16,
},
image: {
flex: 1,
justifyContent: "center",
},
addProductBtn: {
backgroundColor: Colors.black,
marginBottom: 30,
// borderRadius: 30,
// borderWidth: 3,
// borderColor: Colors.white,
},
});