Fix room’s list order and load more

This commit is contained in:
Rodrigo Nascimento 2017-08-12 23:15:00 -03:00
parent d522292a98
commit 03b97c25b1
2 changed files with 10 additions and 7 deletions

View File

@ -98,12 +98,15 @@ export default class RoomView extends React.Component {
} }
onEndReached = () => { onEndReached = () => {
if (this.state.dataSource.length && this.state.loaded && this.state.loadingMore !== true && this.state.end !== true) { const rowCount = this.state.dataSource.getRowCount();
if (rowCount && this.state.loaded && this.state.loadingMore !== true && this.state.end !== true) {
this.setState({ this.setState({
// ...this.state, // ...this.state,
loadingMore: true loadingMore: true
}); });
RocketChat.loadMessagesForRoom(this.rid, this.state.dataSource[this.state.dataSource.length - 1].ts, ({ end }) => {
const lastRowData = this.data[rowCount - 1];
RocketChat.loadMessagesForRoom(this.rid, lastRowData.ts, ({ end }) => {
this.setState({ this.setState({
// ...this.state, // ...this.state,
loadingMore: false, loadingMore: false,
@ -196,8 +199,8 @@ export default class RoomView extends React.Component {
<ListView <ListView
enableEmptySections enableEmptySections
style={styles.list} style={styles.list}
onEndReachedThreshold={0.1} onEndReachedThreshold={10}
ListFooterComponent={this.renderHeader()} renderFooter={this.renderHeader}
onEndReached={this.onEndReached} onEndReached={this.onEndReached}
dataSource={this.state.dataSource} dataSource={this.state.dataSource}
renderRow={item => this.renderItem({ item })} renderRow={item => this.renderItem({ item })}

View File

@ -110,9 +110,9 @@ export default class RoomsListView extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server).sorted('_updatedAt', true); this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server);
this.state = { this.state = {
dataSource: ds.cloneWithRows(this.data.sorted('_updatedAt', true).slice(0, 10)), dataSource: ds.cloneWithRows([]),
searching: false, searching: false,
searchDataSource: [], searchDataSource: [],
searchText: '' searchText: ''
@ -244,7 +244,7 @@ export default class RoomsListView extends React.Component {
updateState = debounce(() => { updateState = debounce(() => {
this.setState({ this.setState({
dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', this.props.server)) dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', this.props.server).sorted('ls', true))
}); });
}, 500); }, 500);