From a4f7aa4853bb3385ed25ef5b1d7f86c58a59420c Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Wed, 4 Nov 2015 11:25:47 -0800 Subject: [PATCH] make onEndReached a little more robust Summary: public Now if you scroll up out of the end threshold and then back down into it, onEndReached will get triggered again. This closes https://github.com/facebook/react-native/issues/1967 This also resets onEndReached when the data source changes. This would fix issues where the data source changes and onEndReached should fire again since the new data may have more pages, whereas the old data had reached the end and stopped. Reviewed By: jingc Differential Revision: D2610799 fb-gh-sync-id: f6cef513a42d4765514bf4bc55d9e31a760117f1 --- Libraries/CustomComponents/ListView/ListView.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/CustomComponents/ListView/ListView.js b/Libraries/CustomComponents/ListView/ListView.js index 067cce83b5..d8edc9dd67 100644 --- a/Libraries/CustomComponents/ListView/ListView.js +++ b/Libraries/CustomComponents/ListView/ListView.js @@ -277,6 +277,7 @@ var ListView = React.createClass({ componentWillReceiveProps: function(nextProps) { if (this.props.dataSource !== nextProps.dataSource) { + this._sentEndForContentLength = null; this.setState((state, props) => { var rowsToRender = Math.min( state.curRenderedRowsCount + props.pageSize, @@ -592,6 +593,12 @@ var ListView = React.createClass({ this._renderMoreRowsIfNeeded(); } + if (this.props.onEndReached && + this._getDistanceFromEnd(this.scrollProperties) > this.props.onEndReachedThreshold) { + // Scrolled out of the end zone, so it should be able to trigger again. + this._sentEndForContentLength = null; + } + this.props.onScroll && this.props.onScroll(e); }, });