-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
78 lines (75 loc) · 2.17 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
import { StatusBar } from 'expo-status-bar';
import { useState } from 'react';
import { Button, Keyboard, KeyboardAvoidingView, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
import Tasks from './Components/Tasks';
export default function App() {
const [tasks, setTasks] = useState([]);
const [input, setInput] = useState();
const addTask = (newTask) => {
Keyboard.dismiss();
setTasks([...tasks, newTask]);
setInput(null);
}
const deleteTask = (index) => {
const tasksArr = [...tasks];
tasksArr.splice(index, 1);
setTasks(tasksArr);
}
return (
<View style={styles.container}>
{/* Today's Tasks */}
<View style={styles.headerView}>
<Text style={styles.headerText}>Today's Tasks</Text>
<View>
{
tasks.map((data, index) => (
<TouchableOpacity onPress={() => deleteTask(index)}>
<Tasks t={data} key={index} />
</TouchableOpacity>
))
}
</View>
</View>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={styles.taskWrapper}
>
<TextInput style={styles.taskInputs} placeholder={'Add a task here'} value={input} onChangeText={Text => setInput(Text)}/>
<Button title="Add Task" style={styles.taskButton} onPress={() => addTask(input)} />
</KeyboardAvoidingView>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#E8EAED',
},
headerView: {
paddingTop: 80,
paddingHorizontal: 40,
},
headerText: {
fontSize: 24,
fontWeight: 'bold'
},
taskWrapper: {
position: 'absolute',
bottom: 10,
width: "100%",
padding: 20,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center'
},
taskInputs: {
backgroundColor: "#fff",
width: "70%",
padding: 10,
borderRadius: 2
},
taskButton: {
width: "20%"
}
});