-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
88 lines (85 loc) · 1.83 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
//import stuff
import React from 'react';
import {View, Text, TextInput, Button, TouchableOpacity} from 'react-native';
//create stuff
class App extends React.Component{
state = {
text: "",
todo: []
}
addTodo = () => {
var newTodo = this.state.text;
var arr = this.state.todo;
arr.push(newTodo);
this.setState({todo: arr, text: ""});
}
deleteTodo = (t) => {
var arr = this.state.todo;
var pos = arr.indexOf(t);
arr.splice(pos, 1);
this.setState({todo: arr});
}
renderTodos = () => {
return this.state.todo.map(t=>{
return (
<TouchableOpacity key={t}>
<Text
style={styles.todo}
onPress={()=>{this.deleteTodo(t)}}
>{t}</Text>
</TouchableOpacity>
)
})
}
render(){
return(
<View style={styles.wholeStyle}>
<View style={styles.viewStyle}>
<Text style={styles.header}>Notes App</Text>
<View style={{marginTop: 10}}/>
<TextInput
style ={styles.inputStyle}
onChangeText={(text)=>this.setState({text})}
value = {this.state.text}
/>
<View style={{marginTop: 10}}/>
<Button
title="Add Todo"
color="#26A69A"
onPress={this.addTodo}
/>
<View style={{marginTop: 100}}/>
{ this.renderTodos() }
</View>
</View>
)
}
}
const styles = {
wholeStyle: {
backgroundColor: "#00796B",
flex: 1
},
viewStyle: {
marginTop: 30,
alignItems: 'center',
justifyContent: 'center',
margin: 10
},
inputStyle: {
height: 40,
borderColor: "white",
borderWidth: 1
},
header: {
fontSize: 30,
color: "white",
fontWeight: "bold"
},
todo: {
fontSize: 24,
color: "white"
}
}
//export stuff
export default App;