-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
136 lines (126 loc) · 3.03 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
135
136
import React, {useState, useEffect} from 'react';
import {
Text,
View,
TextInput,
Pressable,
StyleSheet,
ScrollView,
KeyboardAvoidingView,
Platform,
} from 'react-native';
import {TodoList} from './src/components/TodoList/TodoList';
import uuid from 'react-native-uuid';
const App = () => {
const [todos, setTodos] = useState([]);
const [text, setText] = useState('');
const addTodo = () => {
const title = text;
if (title === '') return;
setTodos(allTodos => [
...allTodos,
{id: uuid.v4(), title: title, complete: false},
]);
setText('');
};
const checkTodo = id => {
const newTodos = [...todos];
const todo = newTodos.find(t => t.id === id);
todo.complete = !todo.complete;
console.log(JSON.stringify(todos, null, 2));
setTodos(newTodos);
};
const clearComplete = () => {
const incompleteTodos = todos.filter(todo => !todo.complete);
setTodos(incompleteTodos);
};
return (
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={style.view}>
<ScrollView style={[style.scrollView]}>
<TodoList todos={todos} checkTodo={checkTodo} />
</ScrollView>
<TextInput
onChangeText={value => setText(value)}
defaultValue={text}
placeholder="What's Next?"
style={[style.textInput]}
/>
<Pressable
onPress={addTodo}
style={({pressed}) => [
style.button,
style.purpleButton,
{opacity: pressed ? 0.8 : 1},
{transform: pressed ? [{scale: 0.97}] : [{scale: 1}]},
]}>
<Text style={style.buttonText}>Add</Text>
</Pressable>
<Pressable
onPress={clearComplete}
style={({pressed}) => [
style.button,
style.greenButton,
{opacity: pressed ? 0.8 : 1},
{transform: pressed ? [{scale: 0.97}] : [{scale: 1}]},
]}>
<Text style={style.buttonText}>Clear</Text>
</Pressable>
</KeyboardAvoidingView>
);
};
const style = StyleSheet.create({
text: {
color: 'blue',
},
scrollView: {
alignSelf: 'stretch',
},
view: {
marginTop: 60,
flex: 1,
alignItems: 'center',
borderTopWidth: 3,
borderTopColor: 'black',
},
textInput: {
marginTop: 36,
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 50,
borderWidth: 3,
borderColor: '#000',
width: 326,
elevation: 3,
fontSize: 25,
fontFamily: 'MabryPro-Medium',
textAlign: 'center',
},
buttonText: {
fontSize: 25,
fontFamily: 'MabryPro-Medium',
},
button: {
marginTop: 30,
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 50,
borderWidth: 3,
borderColor: '#000',
width: 326,
elevation: 3,
},
purpleButton: {
backgroundColor: '#696FFF',
},
greenButton: {
backgroundColor: '#6CFF69',
marginBottom: 40,
},
});
export default App;