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 8cec881..024fe1c 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, - } + }, + forceUpdate: this.props.forceUpdate || 0, + } + } + componentWillReceiveProps(nextProps) { + if (nextProps.forceUpdate != undefined) { + this.setState({forceUpdate: nextProps.forceUpdate}); } } shouldComponentUpdate(nextProps, nextState) { var index = this._index(nextProps); var range = this._pagesRange(nextState); + 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 + this.state.index !== index || (nextProps.forceUpdate != undefined && forceUpdate != nextProps.forceUpdate) ); } componentDidUpdate() {