-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
117 lines (109 loc) · 2.98 KB
/
Copy pathApp.js
File metadata and controls
117 lines (109 loc) · 2.98 KB
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
import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet, FlatList, Keyboard, TextInput, TouchableOpacity } from 'react-native';
import Task from './Components/Task'
const App = () => {
const [keyboardStatus, setKeyboardStatus] = useState(false);
const [task, setTask] = useState();
const [taskItems, setTaskItems] = useState(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"]);
useEffect(() => {
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
setKeyboardStatus(true);
});
const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
setKeyboardStatus(false);
});
return () => {
showSubscription.remove();
hideSubscription.remove();
};
}, []);
const handleAddTask = () => {
console.log(taskItems)
setTaskItems([...taskItems, task]);
setIsKeyboardOpened(false)
setTask(null);
}
const delteTask = (index) => {
let itemscopy = [...taskItems]
itemscopy.splice(index, 1);
setTaskItems(itemscopy);
}
const renderItem = ({ item, index }) => {
return (<TouchableOpacity key={index} onPress={() => delteTask(index)}>
<Task text={item} />
</TouchableOpacity>
)
};
return (
<>
<View style={styles.taskWrapper}>
<Text style={styles.sectionTitle}>Today's Task</Text>
</View>
<View style={{ maxHeight: keyboardStatus ? '68%' : '80%' }}>
<FlatList
data={taskItems}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</View>
<View style={{ flexDirection: 'row', width: '45%', position: 'absolute', bottom: 5, left: 50 }}>
<TextInput style={styles.Input} placeholder={'Write Your Task Here'} value={task} onChangeText={text => setTask(text)} />
<TouchableOpacity onPress={() => handleAddTask()}>
<View style={styles.addWrapper}>
<Text style={styles.addText}>+</Text>
</View>
</TouchableOpacity>
</View>
</>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#E8EAED'
},
taskWrapper: {
paddingTop: 55,
paddingHorizontal: 20,
},
sectionTitle: {
fontSize: 24,
fontWeight: 'bold',
},
items: {
maxHeight: '68%'
// marginTop: 20,
},
writeTaskWrapper: {
alignSelf: 'center'
// position: 'absolute',
// bottom: 5 ,
// width: '100%',
// flexDirection: 'row',
// justifyContent:'center'
// justifyContent: 'space-around',
// alignItems: 'center',
// flex: 1
},
Input: {
paddingVertical: 15,
paddingHorizontal: 15,
backgroundColor: '#FFFF',
borderColor: '#C0C0C0',
borderRadius: 60,
borderWidth: 1,
width: 250,
},
addWrapper: {
width: 60,
height: 60,
backgroundColor: '#FFFF',
borderRadius: 60,
justifyContent: 'center',
alignItems: 'center',
borderColor: '#C0C0C0',
borderWidth: 1,
},
addText: {},
})
export default App;