-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
91 lines (84 loc) · 2.16 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
import { useState } from "react";
import { StyleSheet, Text, View, FlatList, Pressable } from "react-native";
import { StatusBar } from "expo-status-bar";
import TaskTile from "./components/TaskTile";
import InputTask from "./components/InputTask";
export default function App() {
const [tasks, setTasks] = useState([]);
const [modalVisible, setModalVisible] = useState(false);
function inputTaskHandler(enteredTask) {
const id = Math.floor(Math.random() * 1000000000).toString();
setTasks((prevTasks) => {
return [...prevTasks, { id: id, text: enteredTask }];
});
}
function deleteTaskHandler(id) {
setTasks((tasks) => {
return tasks.filter((task) => task.id !== id);
});
}
return (
<>
<StatusBar style="auto" />
<View style={styles.app}>
<Pressable style={styles.button} onPress={() => setModalVisible(true)}>
<Text style={styles.buttonText}>Add Task...</Text>
</Pressable>
{modalVisible && (
<InputTask
tasks={tasks}
onAddTask={inputTaskHandler}
modalVisible={modalVisible}
setModalVisible={setModalVisible}
/>
)}
<View style={styles.listLayout}>
<Text style={styles.heading}>Your Tasks...</Text>
<FlatList
data={tasks}
renderItem={(task) => {
return (
<TaskTile
text={task.item.text}
id={task.item.id}
onDeleteTask={deleteTaskHandler}
/>
);
}}
keyExtractor={(item) => item.id}
/>
</View>
</View>
</>
);
}
const styles = StyleSheet.create({
app: {
flex: 1,
alignItems: "center",
backgroundColor: "pink",
paddingTop: 60,
padding: 20,
},
listLayout: {
flex: 5,
marginTop: 20,
width: "100%",
},
heading: {
fontSize: 20,
fontWeight: "900",
color: "maroon",
marginBottom: 10,
},
button: {
backgroundColor: "maroon",
alignItems: "center",
borderRadius: 10,
padding: 10,
width: "30%",
},
buttonText: {
color: "white",
},
});