-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
134 lines (128 loc) · 3.36 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { StatusBar } from 'expo-status-bar';
import React, {useState} from "react";
import { Platform, SafeAreaView, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
export default function App() {
const [text, setText] = useState("");
const [toDos, setToDos] = useState({});
const onChangeText = (event) => {
setText(event);
}
const addToDo = () => {
if (text === "") {
return;
}
const newToDos = Object.assign({}, toDos, {[Date.now()]: {text, isDone: false}}); // const newToDos = {...todos, [Date.now()]:{text}}; 해도 동일함
setToDos(newToDos);
setText("");
}
const toggleDone = (key) => {
const updatedToDos = {...toDos,
[key]: {
...toDos[key],
isDone: !toDos[key].isDone,
},
};
setToDos(updatedToDos);
}
return (
<SafeAreaView style = {styles.safeContainer}>
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.title}>Appdong ToDo List</Text>
</View>
<View>
<TextInput
placeholder={"할 일을 추가하세요"}
value={text}
style={styles.input}
onChangeText={onChangeText}
onSubmitEditing={addToDo}
/>
</View>
<View style={styles.toDoContainer}>
<Text>Daily To Do</Text>
{
Object.keys(toDos).map(key => toDos[key].isDone === false &&
<View style={styles.toDo} key={key}>
<TouchableOpacity style={styles.checkBox} onPress={() => toggleDone(key)}>
</TouchableOpacity>
<Text style={styles.toDoText}>{toDos[key].text}</Text>
</View>
)
}
</View>
<View style={styles.toDoContainer}>
<Text>Done</Text>
{
Object.keys(toDos).map(key => toDos[key].isDone === true &&
<View style={styles.toDo} key={key}>
<TouchableOpacity style={[styles.checkBox, styles.checkedBox]} onPress={() => toggleDone(key)}>
<Text style={{color:"white"}}>✔</Text>
</TouchableOpacity>
<Text style={[styles.toDoText,styles.doneToDoText]}>{toDos[key].text}</Text>
</View>
)
}
</View>
<StatusBar hidden/>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safeContainer: {
flex: 1,
backgroundColor: "white",
},
container: {
flex: 1,
paddingHorizontal: 15, // SafeAreaView 사용 시 ios에선 padding 적용되지 않음
marginHorizontal: Platform.OS == "android" ? 0 : 15,
},
header: {
marginTop: 20,
},
title: {
fontSize: 28,
},
input: {
borderWidth: 1,
paddingVertical: 15,
paddingHorizontal: 20,
borderRadius: 30,
marginTop: 20,
fontSize: 18
},
toDoContainer: {
marginTop: 50,
},
toDo: {
borderRadius: 10,
borderWidth: 1,
borderColor: "lightgrey",
paddingHorizontal: 20,
paddingVertical: 20,
marginVertical: 3,
backgroundColor: "white",
flexDirection: "row",
justifyContent: "space-between"
},
toDoText: {
fontSize: 15,
},
checkBox: {
borderWidth: 1,
borderColor: "grey",
height: 15,
width: 15,
},
checkedBox: {
backgroundColor: "skyblue",
alignItems: "center",
justifyContent: "center",
},
doneToDoText: {
textDecorationLine: "line-through",
color: "grey",
}
});