-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
114 lines (94 loc) · 2.58 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
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, TextInput, KeyboardAvoidingView, TouchableOpacity, ImageBackground} from 'react-native';
import { useState } from 'react';
import Task from './components/Task';
const image = {uri: 'https://images.pexels.com/photos/1495580/pexels-photo-1495580.jpeg?auto=compress&cs=tinysrgb&w=600'}
export default function App() {
const [task, setTask] = useState();
const [taskItems, setTaskItems] = useState([]);
const handleTask =()=>{
Keyboard.dismiss();
setTaskItems([...taskItems, task])
setTask(null);
}
//Delete task when completed
const completeTask=(index)=>{
let itemsCopy = [...taskItems];
itemsCopy.splice(index, 1)
}
return (
<View style={styles.container}>
<ImageBackground source={image} resizeMode="cover" style={styles.image}>
<View style={styles.tasksWrapper}>
<View style={styles.title}><Text>Tasks to do</Text>
<View>
{
taskItems.map((item, index)=>{
return(
<TouchableOpacity key={index} onPress={()=> completeTask(index)}>
<Task text={item} />
</TouchableOpacity>
)
})
}
</View>
</View>
</View>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={styles.writeTaskWrapper}><TextInput style={styles.input} placeholder={'Add a new task'} value={task} onChangeText={text => setTask(text)}/>
<TouchableOpacity onPress={()=> handleTask()}>
<View style={styles.addWrapper}>
<Text style={styles.addText}>+</Text>
</View>
</TouchableOpacity>
</KeyboardAvoidingView>
</ImageBackground>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#E8EAED',
},
image: {
flex: 1,
},
tasksWrapper: {
paddingTop: 80,
paddingHorizontal: 20,
},
title: {
fontSize: 34,
fontWeight: 'bold'
},
writeTaskWrapper: {
position: 'absolute',
bottom: 60,
width: '100%',
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center'
},
addWrapper: {
width: 60,
height: 60,
backgroundColor: '#FFF',
borderRadius: 60,
justifyContent: 'center',
alignItems: 'center',
borderColor: '#C0C0C0',
borderWidth: 1,
},
input: {
paddingVertical: 15,
paddingHorizontal: 15,
backgroundColor: '#FFF',
borderRadius: 60,
paddingBottom: 20,
borderColor: '#C0C0C0',
borderWidth: 1,
width: 250,
},
});