-
Notifications
You must be signed in to change notification settings - Fork 4
/
App.js
97 lines (90 loc) · 2.25 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
import React, { useState } from 'react';
import { Text, View, TextInput, TouchableOpacity, Keyboard, KeyboardAvoidingView, ScrollView, StyleSheet } from 'react-native';
import Task from './components/Task/Task'
export default function App() {
const [task, setTask] = useState();
const [taskList, setTaskList] = useState([]);
const addTask = () => {
Keyboard.dismiss();
setTaskList([...taskList, task])
setTask(null);
}
return (
<View style={styles.container}>
<Text style={styles.sectionTitle}>Today's to do list 📝</Text>
<View style={styles.tasksWrapper}>
<ScrollView
style={styles.items}
>
{
taskList.map((item, index) => {
return (
<Task text={item} key={index} />
)
})
}
</ScrollView>
</View>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={styles.inputTask}
>
<TextInput style={styles.input} placeholder={'Write a task'} value={task} onChangeText={text => setTask(text)} />
<TouchableOpacity onPress={() => addTask()}>
<View style={styles.addButton}>
<Text>+</Text>
</View>
</TouchableOpacity>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#a3b18a',
},
tasksWrapper: {
height: '80%'
},
sectionTitle: {
marginTop: 70,
paddingHorizontal: 20,
fontSize: 24,
fontWeight: 'bold',
color: 'white'
},
items: {
marginTop: 10,
marginBottom: 10,
maxHeight: '87%',
paddingHorizontal: 20,
},
inputTask: {
position: 'absolute',
bottom: 60,
width: '100%',
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center'
},
input: {
paddingVertical: 15,
paddingHorizontal: 15,
backgroundColor: '#FFF',
borderRadius: 60,
borderColor: '#588157',
borderWidth: 2,
width: 250,
},
addButton: {
width: 60,
height: 60,
backgroundColor: '#FFF',
borderRadius: 60,
justifyContent: 'center',
alignItems: 'center',
borderColor: '#588157',
borderWidth: 2,
}
});