-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
120 lines (108 loc) · 2.78 KB
/
App.js
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
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TextInput,
Button,
FlatList,
Image,
} from "react-native";
import GoalItem from "./components/GoalItem.js";
import GoalInput from "./components/GoalInput.js";
import { TouchableOpacity } from "react-native-gesture-handler";
export default function App() {
const [courseGoals, setCourseGoals] = useState([]);
const [isAddMode, setIsAddMode] = useState(false);
const addGoalHandler = (goalTitle) => {
setCourseGoals((currentGoals) => [
...currentGoals,
{ id: Math.random().toString(), value: goalTitle },
]);
setIsAddMode(false);
};
const removeGoalHandler = (goalId) => {
setCourseGoals((currentGoals) => {
return currentGoals.filter((goal) => goal.id !== goalId);
});
};
const cancelGoalAdditionHandler = () => {
setIsAddMode(false);
};
// in GoalInput we ve passed onAddGoal as a prop which calls addGoalHadler function
// onDelete should point out to a function
TouchableOpacity.defaultProps = { activeOpacity: 1.0 };
return (
<View style={styles.screen}>
<View style={styles.container}>
<Image source={require("./assets/img3.jpg")} style={styles.image} />
<Image
source={require("./assets/GoalsHack.png")}
style={styles.image1}
/>
</View>
<TouchableOpacity activeOpacity={0.6}>
<View style={styles.addmore}>
{/*{
<Button
title="Add Your New Goal"
color="#3d0019"
onPress={() => setIsAddMode(true)}
/>
*/}
</View>
</TouchableOpacity>
<GoalInput
visible={isAddMode}
onAddGoal={addGoalHandler}
onCancel={cancelGoalAdditionHandler}
/>
<FlatList
keyExtractor={(item, index) => item.id}
data={courseGoals}
renderItem={(itemData) => (
<GoalItem
id={itemData.item.id}
onDelete={removeGoalHandler}
title={itemData.item.value}
/>
)}
/>
</View>
);
}
const styles = StyleSheet.create({
screen: {
padding: 50,
},
Icontainer: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
image: {
flex: 1,
alignItems: "center",
position: "absolute",
justifyContent: "center",
resizeMode: "cover",
paddingRight: 300,
},
image1: {
flex: 1,
alignItems: "center",
position: "absolute",
justifyContent: "center",
resizeMode: "cover",
paddingRight: 300,
},
container: {
height: "100%",
justifyContent: "center",
paddingBottom: 650,
position: "absolute",
},
addmore: {
color: "#66002a",
},
}); //stylesheet because it automatically give validation