From d217921b5eca81752d47831c362065bfefc733e7 Mon Sep 17 00:00:00 2001 From: zongwan Date: Tue, 20 Jun 2017 18:51:39 -0700 Subject: [PATCH] Update VirtualizedList.js, fix wrong position after scrollToEnd when props.refreshing === true Summary: Pull request again for clean branch Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. What existing problem does the pull request solve? Fix #14033 Fix wrong position after `scrollToEnd` when `props.refreshing === true` **Before** ![before](https://cloud.githubusercontent.com/assets/1185694/26242273/657f0180-3cba-11e7-9360-49269fd1bb2f.gif) **After** ![after](https://cloud.githubusercontent.com/assets/1185694/26242503/465a856c-3cbb-11e7-98fb-f3256fd45c15.gif) Sign the [CLA][2], if you haven't already. Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged. For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines. [1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9 [2]: https://code.facebook.com/cla [3]: https://travis-ci.org/facebook/react-native [4]: http://circleci.com/gh/facebook/react-native [5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests Closes https://github.com/facebook/react-native/pull/14089 Differential Revision: D5283973 Pulled By: sahrens fbshipit-source-id: 9bef9a922c15aa5bed11a59acbd7b48a76946d29 --- Libraries/Lists/VirtualizedList.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index cdac64df63f3c9..21abddc9338954 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -209,11 +209,13 @@ class VirtualizedList extends React.PureComponent { const animated = params ? params.animated : true; const veryLast = this.props.getItemCount(this.props.data) - 1; const frame = this._getFrameMetricsApprox(veryLast); - const offset = + const offset = Math.max( + 0, frame.offset + - frame.length + - this._footerLength - - this._scrollMetrics.visibleLength; + frame.length + + this._footerLength - + this._scrollMetrics.visibleLength, + ); this._scrollRef.scrollTo( this.props.horizontal ? {x: offset, animated} : {y: offset, animated}, );