...
|
...
|
@@ -13,14 +13,15 @@ import ReactNative, { |
|
|
Platform,
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
|
import MessageCell from './MessageCell';
|
|
|
|
|
|
export default class Message extends Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
|
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
this.renderRow = this.renderRow.bind(this);
|
|
|
this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this);
|
|
|
|
|
|
this.dataSource = new ListView.DataSource({
|
|
|
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
|
...
|
...
|
@@ -28,37 +29,49 @@ export default class Message extends Component { |
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
this.trigggePullToRefresh();
|
|
|
}
|
|
|
|
|
|
trigggePullToRefresh() {
|
|
|
if (Platform.OS === 'ios') {
|
|
|
InteractionManager.runAfterInteractions(() => {
|
|
|
this.listView && this.listView.getScrollResponder().startPullToRefresh();
|
|
|
});
|
|
|
} else {
|
|
|
this.props.onRefresh && this.props.onRefresh();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_renderRow(rowData: object, sectionID: number, rowID: number) {
|
|
|
renderRow(rowData, sectionID, rowID) {
|
|
|
|
|
|
return (
|
|
|
<TouchableOpacity
|
|
|
onPress={() => {
|
|
|
console.log(rowID)
|
|
|
}}
|
|
|
>
|
|
|
<View style={styles.rowContainer}>
|
|
|
<Text>{rowData.get('title')}</Text>
|
|
|
<Text>{rowData.get('detail')}</Text>
|
|
|
</View>
|
|
|
</TouchableOpacity>
|
|
|
);
|
|
|
return <MessageCell
|
|
|
rowID={rowID}
|
|
|
data={rowData}
|
|
|
onPressListItem={this.props.onPressListItem}
|
|
|
/>;
|
|
|
}
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
let dataSource = this.props.data.dataSource.toArray();
|
|
|
let {defaults, latest} = this.props.data;
|
|
|
let dataSource = defaults.toArray();
|
|
|
let isPullToRefresh = latest.isFetching;
|
|
|
|
|
|
return (
|
|
|
<View style={styles.container}>
|
|
|
<ListView
|
|
|
ref={(c) => {
|
|
|
this.listView = c;
|
|
|
}}
|
|
|
contentContainerStyle={styles.contentContainer}
|
|
|
dataSource={this.dataSource.cloneWithRows(dataSource)}
|
|
|
renderRow={this._renderRow}
|
|
|
renderRow={this.renderRow}
|
|
|
enableEmptySections={true}
|
|
|
enablePullToRefresh={true}
|
|
|
isOnPullToRefresh={isPullToRefresh}
|
|
|
onRefreshData={() => {
|
|
|
this.props.onRefresh && this.props.onRefresh();
|
|
|
}}
|
|
|
/>
|
|
|
</View>
|
|
|
);
|
...
|
...
|
@@ -70,12 +83,9 @@ let {width, height} = Dimensions.get('window'); |
|
|
let styles = StyleSheet.create({
|
|
|
container: {
|
|
|
flex: 1,
|
|
|
backgroundColor: '#f0f0f0',
|
|
|
backgroundColor: 'white',
|
|
|
},
|
|
|
contentContainer: {
|
|
|
|
|
|
},
|
|
|
rowContainer: {
|
|
|
|
|
|
},
|
|
|
}); |
...
|
...
|
|