-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
105 lines (100 loc) · 2.06 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
import React, { useState } from 'react'
import {
StyleSheet,
View,
Text,
TextInput,
Button,
FlatList,
} from 'react-native'
export default function App() {
const [todo, setTodo] = useState([])
const [todoInputValue, setTodoInputValueChange] = useState('')
const addTodo = () => {
if (todoInputValue.length > 0) {
const singleTodo = {
id: todo.length + 1,
task: todoInputValue,
}
setTodo([...todo, singleTodo])
setTodoInputValueChange('')
}
}
const deleteTodo = (deleteId) => {
const newTodo = todo.filter((item) => item.id !== deleteId)
setTodo(newTodo)
}
return (
<View style={styles.container}>
<View style={styles.heading}>
<Text style={styles.title}> Simple Todo App</Text>
</View>
<View style={styles.todoContainer}>
<TextInput
style={styles.addTodoInput}
onChangeText={(text) => setTodoInputValueChange(text)}
value={todoInputValue}
placeholder='Add task'
/>
<Button title='Add' color='#4374c1' onPress={() => addTodo()} />
<FlatList
data={todo}
renderItem={({ item }) => (
<View style={styles.todoListing}>
<Text style={styles.todoListItem}>{item.task}</Text>
<Button
title='Delete'
color='#fc6064'
onPress={() => deleteTodo(item.id)}
/>
</View>
)}
keyExtractor={(item) => item.id}
/>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f6fbfe',
},
heading: {
marginTop: 50,
padding: 20,
backgroundColor: '#010535',
textAlign: 'center',
},
title: {
fontWeight: '700',
textTransform: 'uppercase',
color: '#fff',
fontSize: 25,
},
todoContainer: {
marginTop: 30,
padding: 30,
},
addTodoInput: {
height: 40,
padding: 5,
color: '#000',
marginBottom: 10,
borderBottomWidth: 2,
borderBottomColor: 'grey',
},
todoListing: {
backgroundColor: '#010535',
marginTop: 30,
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
padding: 20,
borderRadius: 5,
},
todoListItem: {
color: '#fff',
fontSize: 25,
},
})