From 04e3c23e677a1cf07d1f5cbd7656050d9d8cec25 Mon Sep 17 00:00:00 2001 From: Gethin Webster Date: Thu, 22 Dec 2016 14:18:37 +0100 Subject: [PATCH] [fix] ListView updates rows when dataSource changes Close #295 --- src/components/ListView/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/ListView/index.js b/src/components/ListView/index.js index c3ce3631..5aa19e00 100644 --- a/src/components/ListView/index.js +++ b/src/components/ListView/index.js @@ -59,6 +59,20 @@ class ListView extends Component { }); } + componentWillReceiveProps(nextProps: Object) { + if (this.props.dataSource !== nextProps.dataSource || this.props.initialListSize !== nextProps.initialListSize) { + this.setState((state, props) => { + this._prevRenderedRowsCount = 0; + return { + curRenderedRowsCount: Math.min( + Math.max(state.curRenderedRowsCount, props.initialListSize), + props.enableEmptySections ? props.dataSource.getRowAndSectionCount() : props.dataSource.getRowCount() + ) + }; + }, () => this._renderMoreRowsIfNeeded()); + } + } + componentDidUpdate() { requestAnimationFrame(() => { this._measureAndUpdateScrollProps();