forked from cobuildlab/react-native-task-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
72 lines (65 loc) · 1.74 KB
/
App.js
File metadata and controls
72 lines (65 loc) · 1.74 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
import React from 'react';
import {
createSwitchNavigator,
} from 'react-navigation';
import {
createAppContainer
} from 'react-navigation';
import {FlatList, StyleSheet, Text, View, TextInput, Button} from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 22
},
item: {
padding: 10,
fontSize: 18,
height: 44,
},
});
class TaskList extends React.Component {
constructor(props) {
super(props);
this.state = {
text: '',
tasks: []
}
}
render() {
return (
<View style={styles.container}>
<FlatList
data={this.state.tasks.map(item => {
return {key: item}
})}
renderItem={({item}) => <Text style={styles.item}>{item.key}</Text>}
/>
<TextInput
style={{height: 40}}
placeholder="Add a new Task"
onChangeText={(text) => this.setState({text})}
value={this.state.text}
/>
<Button
onPress={() => {
const newTasks = this.state.tasks;
newTasks.push(this.state.text);
this.setState({tasks: newTasks, text: ''})
}}
title="Add Task"
color="#841584"
/>
</View>
);
}
}
const SwitchNavigator = createSwitchNavigator(
{
'TaskList': TaskList,
},
{
initialRouteName: 'TaskList',
},
);
const App = createAppContainer(SwitchNavigator);
export default App;