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
This commit is contained in:
zongwan 2017-06-20 18:51:39 -07:00 committed by Facebook Github Bot
parent 112e3767ce
commit d217921b5e
1 changed files with 6 additions and 4 deletions

View File

@ -209,11 +209,13 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, State> {
const animated = params ? params.animated : true; const animated = params ? params.animated : true;
const veryLast = this.props.getItemCount(this.props.data) - 1; const veryLast = this.props.getItemCount(this.props.data) - 1;
const frame = this._getFrameMetricsApprox(veryLast); const frame = this._getFrameMetricsApprox(veryLast);
const offset = const offset = Math.max(
0,
frame.offset + frame.offset +
frame.length + frame.length +
this._footerLength - this._footerLength -
this._scrollMetrics.visibleLength; this._scrollMetrics.visibleLength,
);
this._scrollRef.scrollTo( this._scrollRef.scrollTo(
this.props.horizontal ? {x: offset, animated} : {y: offset, animated}, this.props.horizontal ? {x: offset, animated} : {y: offset, animated},
); );