From 6e94a8c2c7b1a239c8370cc8d1aba2c41c0560f9 Mon Sep 17 00:00:00 2001 From: Reza Ghorbani Date: Wed, 11 May 2016 11:45:13 +0430 Subject: [PATCH 1/2] added force update --- src/index.ios.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.ios.js b/src/index.ios.js index 8cec881..2258bf4 100644 --- a/src/index.ios.js +++ b/src/index.ios.js @@ -22,16 +22,23 @@ export default class InfiniteScrollView extends Component { size: { width: 0, height: 0, - } + }, + shouldUpdate: this.props.shouldUpdate || 0, + } + } + componentWillReceiveProps(nextProps) { + if (nextProps.shouldUpdate != undefined) { + this.setState({shouldUpdate: nextProps.shouldUpdate}); } } shouldComponentUpdate(nextProps, nextState) { var index = this._index(nextProps); var range = this._pagesRange(nextState); + var shouldUpdate = this.state.shouldUpdate; return ( nextState.size !== this.state.size || range.to !== this._renderedRange.to || range.from !== this._renderedRange.from || - this.state.index !== index + this.state.index !== index || (nextProps.shouldUpdate != undefined && shouldUpdate != nextProps.shouldUpdate) ); } componentDidUpdate() { From 8e00255e152dc980c00360b49f607f7399cb15db Mon Sep 17 00:00:00 2001 From: Reza Ghorbani Date: Wed, 11 May 2016 11:49:39 +0430 Subject: [PATCH 2/2] added force update doc to README --- README.md | 1 + src/index.ios.js | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1338287..1434151 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Component wraps ScrollView so all ScrollView properties are available. - **toIndex** - Optional - (Integer) - Don't allow scrolling below this page index. - **fromIndex** - Optional - (Integer) - Don't allow scrolling above this page index. - **onPageIndexChange** - Optional - (Function) - Called when page index is changed (user scrolled). +- **forceUpdate** - Optional - (Number) - Forces render be called if it changes. ### Known issues Currently only iOS is supported. Android support is coming. diff --git a/src/index.ios.js b/src/index.ios.js index 2258bf4..024fe1c 100644 --- a/src/index.ios.js +++ b/src/index.ios.js @@ -23,22 +23,22 @@ export default class InfiniteScrollView extends Component { width: 0, height: 0, }, - shouldUpdate: this.props.shouldUpdate || 0, + forceUpdate: this.props.forceUpdate || 0, } } componentWillReceiveProps(nextProps) { - if (nextProps.shouldUpdate != undefined) { - this.setState({shouldUpdate: nextProps.shouldUpdate}); + if (nextProps.forceUpdate != undefined) { + this.setState({forceUpdate: nextProps.forceUpdate}); } } shouldComponentUpdate(nextProps, nextState) { var index = this._index(nextProps); var range = this._pagesRange(nextState); - var shouldUpdate = this.state.shouldUpdate; + var forceUpdate = this.state.forceUpdate; return ( nextState.size !== this.state.size || range.to !== this._renderedRange.to || range.from !== this._renderedRange.from || - this.state.index !== index || (nextProps.shouldUpdate != undefined && shouldUpdate != nextProps.shouldUpdate) + this.state.index !== index || (nextProps.forceUpdate != undefined && forceUpdate != nextProps.forceUpdate) ); } componentDidUpdate() {