-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
118 lines (113 loc) · 2.48 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
import React, { useState } from "react";
import {
Keyboard,
KeyboardAvoidingView,
Platform,
ScrollView,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
import Task from "./Task";
export default function App() {
const [task, setTask] = useState();
const [taskItems, setTaskItems] = useState([]);
const addTask = () => {
Keyboard.dismiss();
setTaskItems([...taskItems, task]);
setTask(null);
};
const removeTask = (id) => {
let taskCopy = [...taskItems];
taskCopy.splice(id, 1);
setTaskItems(taskCopy);
};
return (
<View style={styles.container}>
<Text style={styles.heading}>TODO APP</Text>
<ScrollView>
{taskItems.map((item, id) => (
<TouchableOpacity key={id} onPress={() => removeTask(id)}>
<Task task={item} />
</TouchableOpacity>
))}
</ScrollView>
<KeyboardAvoidingView
style={styles.inputWrapper}
behavior={Platform.OS === "ios" ? "padding" : "height"}
>
<TextInput
style={styles.input}
placeholder="Task to do"
value={task}
onChangeText={(text) => setTask(text)}
/>
<TouchableOpacity onPress={addTask} style={styles.button}>
<Text style={styles.buttonText}>+</Text>
</TouchableOpacity>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#efefef",
},
heading: {
fontSize: 40,
paddingTop: 80,
color: "darkblue",
opacity: 0.7,
paddingHorizontal: 20,
fontWeight: "bold",
},
inputWrapper: {
width: "100%",
position: "absolute",
bottom: 0,
padding: 20,
flexDirection: "row",
backgroundColor: "#efefef",
alignItems: "center",
justifyContent: "space-between",
paddingHorizontal: 20,
},
input: {
width: "80%",
backgroundColor: "white",
padding: 15,
borderRadius: 30,
fontSize: 17,
shadowColor: "#000",
shadowOffset: {
width: 3,
height: 5,
},
shadowOpacity: 1,
shadowRadius: 5,
elevation: 6,
},
button: {
width: 50,
height: 50,
backgroundColor: "white",
justifyContent: "center",
alignItems: "center",
borderRadius: 50,
shadowColor: "#000",
shadowOffset: {
width: 3,
height: 5,
},
shadowOpacity: 1,
shadowRadius: 5,
elevation: 6,
},
buttonText: {
fontSize: 25,
opacity: 0.6,
},
});