|
@@ -1,5 +1,7 @@
|
|
|
import React, { Component } from "react";
|
|
|
import {
|
|
|
+ Keyboard,
|
|
|
+ ListView,
|
|
|
Platform,
|
|
|
StyleSheet,
|
|
|
Text,
|
|
@@ -7,6 +9,7 @@ import {
|
|
|
} from "react-native";
|
|
|
import Header from "./header";
|
|
|
import Footer from "./footer";
|
|
|
+import Row from "./row";
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
container: {
|
|
@@ -20,19 +23,31 @@ const styles = StyleSheet.create({
|
|
|
},
|
|
|
content: {
|
|
|
flex: 1
|
|
|
+ },
|
|
|
+ list: {
|
|
|
+ backgroundColor: "#fff"
|
|
|
+ },
|
|
|
+ separator: {
|
|
|
+ borderWidth: 2,
|
|
|
+ borderColor: "#eee"
|
|
|
}
|
|
|
});
|
|
|
|
|
|
class App extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
+ const ds = new ListView.DataSource({
|
|
|
+ rowHasChanged: (r1, r2) => r1 !== r2
|
|
|
+ });
|
|
|
this.state = {
|
|
|
allComplete: false,
|
|
|
+ dataSource: ds.cloneWithRows([]),
|
|
|
items: [],
|
|
|
value: ""
|
|
|
};
|
|
|
this.handleAddItem = this.handleAddItem.bind(this);
|
|
|
this.handleToggleAllComplete = this.handleToggleAllComplete.bind(this);
|
|
|
+ this.setSource = this.setSource.bind(this);
|
|
|
}
|
|
|
|
|
|
handleAddItem() {
|
|
@@ -47,10 +62,7 @@ class App extends Component {
|
|
|
complete: false
|
|
|
}
|
|
|
];
|
|
|
- this.setState({
|
|
|
- items: newItems,
|
|
|
- value: ""
|
|
|
- });
|
|
|
+ this.setSource(newItems, newItems, { value: "" });
|
|
|
}
|
|
|
|
|
|
handleToggleAllComplete() {
|
|
@@ -59,15 +71,12 @@ class App extends Component {
|
|
|
...item,
|
|
|
complete
|
|
|
}));
|
|
|
- console.table(newItems);
|
|
|
- this.setState({
|
|
|
- allComplete: complete,
|
|
|
- items: newItems
|
|
|
- });
|
|
|
+
|
|
|
+ this.setSource(newItems, newItems, { allComplete: complete });
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- console.log(this.state);
|
|
|
+
|
|
|
return (
|
|
|
<View style={styles.container}>
|
|
|
<Header
|
|
@@ -76,11 +85,39 @@ class App extends Component {
|
|
|
onToggleAllComplete={this.handleToggleAllComplete}
|
|
|
value={this.state.value}
|
|
|
/>
|
|
|
- <View style={styles.content} />
|
|
|
+ <View style={styles.content}>
|
|
|
+ <ListView
|
|
|
+ enableEmptySections
|
|
|
+ dataSource={this.state.dataSource}
|
|
|
+ onScroll={() => Keyboard.dismiss()}
|
|
|
+ renderRow={({ key, ...value }) => {
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Row
|
|
|
+ key={key}
|
|
|
+ { ...value }
|
|
|
+ />
|
|
|
+ );
|
|
|
+ }}
|
|
|
+ renderSeparator={(sectionId, rowId) => {
|
|
|
+
|
|
|
+ return <View key={rowId} style={styles.separator} />;
|
|
|
+ }}
|
|
|
+ style={styles.list}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
<Footer />
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ setSource(items, itemsDataSource, otherState = {}) {
|
|
|
+ this.setState({
|
|
|
+ items,
|
|
|
+ dataSource: this.state.dataSource.cloneWithRows(itemsDataSource),
|
|
|
+ ...otherState
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export default App;
|