2017-05-09 22:46:54 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux'
|
2017-05-16 21:12:37 +02:00
|
|
|
import { ListView, Text, TouchableHighlight, Switch, View } from 'react-native';
|
2017-05-11 22:14:01 +02:00
|
|
|
import { Log } from 'src/log.js';
|
2017-05-16 21:12:37 +02:00
|
|
|
import Checkbox from 'react-native-checkbox';
|
2017-05-09 22:46:54 +02:00
|
|
|
import { _ } from 'src/locale.js';
|
|
|
|
|
|
|
|
class ItemListComponent extends Component {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2017-05-15 22:50:14 +02:00
|
|
|
const ds = new ListView.DataSource({
|
|
|
|
rowHasChanged: (r1, r2) => { return r1 !== r2; }
|
|
|
|
});
|
|
|
|
this.state = {
|
|
|
|
dataSource: ds,
|
|
|
|
items: [],
|
|
|
|
selectedItemIds: [],
|
|
|
|
};
|
2017-05-09 22:46:54 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 21:12:37 +02:00
|
|
|
componentWillMount() {
|
|
|
|
const newDataSource = this.state.dataSource.cloneWithRows(this.props.items);
|
|
|
|
this.state = { dataSource: newDataSource };
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:46:54 +02:00
|
|
|
componentWillReceiveProps(newProps) {
|
|
|
|
// https://stackoverflow.com/questions/38186114/react-native-redux-and-listview
|
2017-05-15 22:50:14 +02:00
|
|
|
this.setState({
|
2017-05-24 22:18:09 +02:00
|
|
|
dataSource: this.state.dataSource.cloneWithRows(newProps.items),
|
2017-05-15 22:50:14 +02:00
|
|
|
});
|
|
|
|
}
|
2017-05-15 21:46:34 +02:00
|
|
|
|
2017-05-15 22:50:14 +02:00
|
|
|
listView_itemPress = (itemId) => {}
|
|
|
|
|
2017-05-09 22:46:54 +02:00
|
|
|
render() {
|
2017-05-15 22:50:14 +02:00
|
|
|
let renderRow = (item) => {
|
2017-05-09 22:46:54 +02:00
|
|
|
let onPress = () => {
|
2017-05-15 22:50:14 +02:00
|
|
|
this.listView_itemPress(item.id);
|
|
|
|
}
|
|
|
|
let onLongPress = () => {
|
|
|
|
this.listView_itemLongPress(item.id);
|
2017-05-09 22:46:54 +02:00
|
|
|
}
|
|
|
|
return (
|
2017-05-15 22:50:14 +02:00
|
|
|
<TouchableHighlight onPress={onPress} onLongPress={onLongPress}>
|
2017-05-16 21:12:37 +02:00
|
|
|
<View>
|
2017-05-24 22:18:09 +02:00
|
|
|
<Text>{item.title} [{item.id}]</Text>
|
2017-05-16 21:12:37 +02:00
|
|
|
</View>
|
2017-05-09 22:46:54 +02:00
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
2017-05-12 21:54:06 +02:00
|
|
|
|
|
|
|
// `enableEmptySections` is to fix this warning: https://github.com/FaridSafi/react-native-gifted-listview/issues/39
|
2017-05-09 22:46:54 +02:00
|
|
|
return (
|
|
|
|
<ListView
|
|
|
|
dataSource={this.state.dataSource}
|
|
|
|
renderRow={renderRow}
|
2017-05-12 21:54:06 +02:00
|
|
|
enableEmptySections={true}
|
2017-05-09 22:46:54 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 21:10:00 +02:00
|
|
|
export { ItemListComponent };
|