Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
109 lines (99 loc) · 2.24 KB
/
Copy pathApp.js
File metadata and controls
109 lines (99 loc) · 2.24 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { Component } from 'react';
import { Text, View, StyleSheet, Button, ScrollView, Switch} from 'react-native';
import Inputs from './input'
/*import { Constants } from 'expo';
import { Card } from 'react-native-elements';
*/
let id = 0;
const styles = StyleSheet.create(
{
todoContainer: {
flexDirection: 'row',
alignItems: 'center',
},
appContainer: {
paddingTop: 5
}
}
);
const Todo = props => (
<View style={styles.todoContainer}>
<Switch onValueChange={props.onToggle} value={props.todo.checked} />
<Button onPress={props.onDelete} title="delete" />
<Text>{props.todo.text}</Text>
</View>
)
export default class App extends Component {
constructor() {
super();
this.state = {
todos: [],
prompt: false,
}
}
addTodo(text) {
this.setState({
todos: [
...this.state.todos,
{id: id++, text: text, checked: false},
],
prompt: false,
})
}
removeTodo(id) {
this.setState({
todos: this.state.todos.filter(todo => todo.id !== id)
})
}
toggleTodo(id) {
this.setState({
todos: this.state.todos.map(todo => {
if (todo.id === id) {
todo.checked = !todo.checked
}
return todo;
})
})
}
promptWindow = () => {
return this.state.prompt && (
<Inputs
setText={(text) => this.addTodo(text)}
/>
)
}
enablePrompt() {
this.setState({
prompt: true,
})
}
render() {
return (
<View style={styles.appContainer}>
{this.promptWindow()}
<Text>Todo count: {this.state.todos.length}</Text>
<Text>Unchecked todo count: {this.state.todos
.filter(todo => !todo.checked).length}
</Text>
<Button onPress={() => this.enablePrompt()}
title="Add TODO" />
<ScrollView>
{this.state.todos.map(todo => (
<Todo
onToggle={() => this.toggleTodo(todo.id)}
onDelete={() => this.removeTodo(todo.id)}
todo={todo}
/>
))}
</ScrollView>
</View>
)
}
}