From 4ea0e9d046d26fba2a4cecf2badf0e8054b9423f Mon Sep 17 00:00:00 2001 From: Phuong To Date: Mon, 31 Dec 2018 14:19:40 +0700 Subject: [PATCH] Fix issue Re-renders entire view when adding/removing rows https://github.com/gitim/react-native-sortable-list/issues/47#issuecomment-368285671 --- src/SortableList.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/SortableList.js b/src/SortableList.js index be7d2d0..a27112a 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -99,7 +99,7 @@ export default class SortableList extends Component { componentWillReceiveProps(nextProps) { const {data, order} = this.state; - let {data: nextData, order: nextOrder} = nextProps; + let { data: nextData, order: nextOrder } = nextProps; if (data && nextData && !shallowEqual(data, nextData)) { nextOrder = nextOrder || Object.keys(nextData) @@ -110,6 +110,17 @@ export default class SortableList extends Component { this._resolveRowLayout[key] = resolve; }); }); + // this.setState({ + // animated: false, + // data: nextData, + // containerLayout: null, + // rowsLayouts: null, + // order: nextOrder + // }); + + + + if (nextData.length > data.length) { this.setState({ animated: false, data: nextData, @@ -117,6 +128,15 @@ export default class SortableList extends Component { rowsLayouts: null, order: nextOrder }); + } else { + this.setState({ + // animated: false, + data: nextData, + // containerLayout: null, + // rowsLayouts: null, + order: nextOrder + }); + } } else if (order && nextOrder && !shallowEqual(order, nextOrder)) { this.setState({order: nextOrder});