-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask-list.js
85 lines (73 loc) · 2.04 KB
/
task-list.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
import React, { Component } from 'react';
import { StyleSheet, View, ListView, TouchableHighlight, Text } from 'react-native';
import TaskRow from './task-row';
const styles = StyleSheet.create({
container: {
paddingTop: 25,
backgroundColor: '#F7F7F7',
flex: 1,
justifyContent: 'flex-start',
},
button: {
height: 60,
borderColor: '#05A5D1',
borderWidth: 2,
backgroundColor: '#333',
margin: 20,
justifyContent: 'center',
alignItems: 'center'
},
buttonText: {
color: '#FAFAFA',
fontSize: 20,
fontWeight: '600',
},
});
class TaskList extends Component {
constructor(props, context) {
super(props, context);
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
});
this.state = {
dataSource: ds.cloneWithRows(props.todos),
};
}
componentWillReceiveProps(nextProps) {
const dataSource = this
.state
.dataSource
.cloneWithRows(nextProps.todos);
this.setState({ dataSource });
}
renderRow(todo) {
return (
<TaskRow
onDone={this.props.onDone}
todo={todo}
/>
);
}
render() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
/>
<TouchableHighlight
onPress={this.props.onAddStarted}
style={styles.button}>
<Text
style={styles.buttonText}> Add Task </Text>
</TouchableHighlight>
</View>
);
}
}
TaskList.propTypes = {
onDone: React.PropTypes.func.isRequired,
onAddStarted: React.PropTypes.func.isRequired,
todos: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
};
export default TaskList;