-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTodos.js
executable file
·52 lines (44 loc) · 1.1 KB
/
Todos.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
import React, { Component, PropTypes } from 'react';
import { View, ListView } from 'react-native';
import Todo from './Todo';
const ds = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1.id !== row2.id,
});
class Todos extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: ds.cloneWithRows(props.todos)
};
this.renderRow = this.renderRow.bind(this);
}
renderRow(todo) {
const {onTodoPress} = this.props;
return <Todo todo={todo} onTodoPress={onTodoPress} />;
}
updateDataSource(todos) {
this.setState({
dataSource: ds.cloneWithRows(todos)
});
}
componentWillReceiveProps(newProps) {
this.updateDataSource(newProps.todos);
}
render() {
return (
<View>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
enableEmptySections={true}
automaticallyAdjustContentInsets={false}
/>
</View>
);
}
}
Todos.propTypes = {
todos: PropTypes.array.isRequired,
onTodoPress: PropTypes.func.isRequired
};
export default Todos;