-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
77 lines (70 loc) · 1.89 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
import { StatusBar } from "expo-status-bar";
import {
StyleSheet,
Text,
View,
FlatList,
SafeAreaView,
Alert,
TouchableWithoutFeedback,
Keyboard,
} from "react-native";
import React, { useState } from "react";
import Header from "./components/Header";
import Task from "./components/Task";
import AddTask from "./components/AddTask";
import "react-native-get-random-values";
import { v4 as uuidv4 } from "uuid";
export default function App() {
const [tasks, setTasks] = useState([
{ task: "HTML I", done: true, id: 1 },
{ task: "CSS", done: true, id: 2 },
{ task: "Responsive design", done: true, id: 3 },
]);
const addTask = (text) => {
if (!text) {
Alert.alert('No tasks?', 'Please add a task', [{text: 'OK'}])
} else {
setTasks((prevTasks) => {
return [{ task: text, id: uuidv4() }, ...prevTasks];
});
}
};
const deleteTask = (id) => {
setTasks((prevTasks) => {
return prevTasks.filter(task => task.id != id)
})
}
return (
<TouchableWithoutFeedback onPress={()=> Keyboard.dismiss()}>
<SafeAreaView style={styles.container}>
<Header />
<View style={styles.content}>
<AddTask addTask={addTask} />
<View style={styles.list}>
<FlatList
data={tasks}
renderItem={({ item }) => <Task item={item}
deleteTask = {deleteTask}
/>}
/>
</View>
</View>
</SafeAreaView>
</TouchableWithoutFeedback>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
},
content: {
padding: 30,
flex: 1,
},
list: {
marginTop: 30,
flex: 1,
},
});