react-native-macos/ReactAndroid
Tomas Reimers cbb0ccb185 mActivelyScrolling expected to be true so long as events are being fired.
Summary:
**Problem:**

It was observed that in [this code path](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java#L292) (i.e. horizontal, paging-enabled scroll view) if you tried to programmatically call the scrollTo method within ~1s of the onMomentumScrollEnd event (which should only be called after all scrolling has ended), the scrollView would scroll to the new location, and then scroll BACK to the original location.

For example, assume you had released the scrollView at location B, and the nearest page boundary is A. Then, 1000ms later, you call scrollTo position C. The order of operations would be:

1. Begin scrolling to A from position B (as it is the nearest page boundary)
2. Reach position A
3. Fire onMomentumScrollEnd
4. 1000ms later call scrollTo C
5. scrollView scrolls to C
6. scrollView scrolls BACK to position A (for no apparent reason).

**Reason:**

I suspect this is because the [smoothlyScrollTo](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java#L292) will continue to animate towards A, but the [scrollEvents will not fire](f954f3d9b6/ReactAndroid/src/main/java/com/facebook/react/views/scroll/OnScrollDispatchHelper.java (L45)) as they are too close to each other. So the true order of events is:

1. Begin scrolling to A from position B (as it is the nearest page boundary)

[begin smoothlyScrollTo]
[scroll towards position A]
[mActivelyScrolling is true]

2. Reach position A

[mActivelyScrolling is true]
[scroll towards position A]
[mActivelyScrolling is false, as there is another scrollEvent, but because it is close enough to the same location it is ignored]

3. Fire onMomentumScrollEnd
4. 1000ms later call scrollTo C

[scroll towards position C]

5. scrollView scrolls to C

[scroll towards position A as the original smoothlyScrollTo animation was never completed]

6. scrollView scrolls BACK to position A.

This is an untested hypothesis, but seems to explain the behavior, and the solution is more semantically correct anyway. If there is an easy way to rebuild the android binaries happy to test it myself! Just let me know!

**Solution:**

 Move the mActivelyAnimating outside the mOnScrollDispatchHelper.onScrollChanged helper, because the HorizontalScrollView event should be considered to be animating so long as onScrollChanged events are being fired.
Closes https://github.com/facebook/react-native/pull/15146

Reviewed By: AaaChiuuu

Differential Revision: D5792026

Pulled By: tomasreimers

fbshipit-source-id: 9654fda038d4a687cc32f4c32dc312baa34627ed
2017-09-12 18:30:39 -07:00
..
libs Apply auto-formatter for BUCK files in fbandroid. 2017-02-27 14:04:56 -08:00
src mActivelyScrolling expected to be true so long as events are being fired. 2017-09-12 18:30:39 -07:00
.npmignore Don't publish /ReactAndroid/build to npm, update version on master 2015-10-12 11:11:40 -07:00
DEFS Fix oss build 2017-06-06 08:30:50 -07:00
DevExperience.md CHORE - Remove Trailing Spaces 2016-04-06 09:21:53 -07:00
README.md Add scripts for running tests locally 2016-05-04 08:58:18 -07:00
build.gradle Update OSS Fresco dependency 2017-07-12 07:54:09 -07:00
gradle.properties fixed mockito version 2016-10-04 10:43:35 -07:00
release.gradle Circle CI releases now work with Java 8 2016-10-28 07:58:52 -07:00

README.md

Building React Native for Android

See the docs on the website.

Running tests

When you submit a pull request CircleCI will automatically run all tests. To run tests locally, see Testing.