2016-12-16 67 views
2

我正在使用Firebase child_added列出数据。每当第一行被渲染时,onEndReached被触发。我的代码有问题吗?反应原生onEndReached总是在第一行被渲染时触发

组件

onEndedReached() { 
lastkey = Object.keys(this.props.contacts).pop(); 
// this.props.nextPage(this.props.auth.uid, lastKey); 
console.log('Fire onEndedReached:', lastkey); 
} 

render() { 
return (
    <ListView 
    style={styles.container} 
    enableEmptySections 
    dataSource={this.dataSource} 
    renderRow={this.renderRow} 
    onEndReachedThreshold={50} 
    onEndReached={() => this.onEndedReached()} 
    /> 
) 
} 
} 

行动

export const getContacts = (uid) => { 
    return (dispatch) => { 
    firebase.database().ref(`userContacts/${uid}`) 
     .limitToFirst(20).on('child_added', (contact) => { 
     dispatch({ 
     type: GET_CONTACTS_SUCCESS, 
     payload: { [contact.key]: contact.val() } 
     }) 
    }) 
    } 
} 

减速

const INITIAL_STATE = {}; 

export default (state = INITIAL_STATE, action) => { 
    switch (action.type) { 
    case GET_CONTACTS_SUCCESS: 
     return Object.assign({}, state, action.payload); 
    default: 
     return state; 
    } 
} 
+0

你使用滚动视图作为ListView的容器吗? –

+0

编号我idid不使用 – vzhen

+0

他们改变了> = 0.36版本的行为;当你不想让它触发时,只需在你的'onEndReached'函数中添加安全措施。 – Jan

回答

2

只需添加上你的onEndReached功能保障,当你不希望它开火。例如

。当你刷新列表视图时或者它正在获取数据或者当前数据的长度不符合触发endReached的要求时。把这一切都置于状态。

if(this.state.isEndCountZero || this.state.skip < 15 || this.state.onEndReached || this.state.refreshing || this.state.isLoading) { return; } 
+1

对于数据存储你可以测试'dataStore.getRowCount(0)'。 –

+0

这很奇怪,但当我尝试使用这些东西时出现错误,可能是我应该导入sometings –