[fix] ScrollView scrollEventThrottle logic

Fix #1726
This commit is contained in:
Nicolas Gallagher
2020-09-08 11:22:35 -07:00
parent 214b296c11
commit bb8a1b1455
3 changed files with 6 additions and 9 deletions
-1
View File
@@ -18,7 +18,6 @@
"dependencies": {
"array-find-index": "^1.0.2",
"create-react-class": "^15.6.2",
"debounce": "^1.2.0",
"deep-assign": "^3.0.0",
"fbjs": "^1.0.0",
"hyphenate-style-name": "^1.0.3",
@@ -11,7 +11,6 @@ import type { ViewProps } from '../View';
import * as React from 'react';
import { forwardRef, useRef } from 'react';
import debounce from 'debounce';
import StyleSheet from '../StyleSheet';
import View from '../View';
@@ -93,6 +92,7 @@ const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
} = props;
const scrollState = useRef({ isScrolling: false, scrollLastTick: 0 });
const scrollTimeout = useRef(null);
function createPreventableScrollHandler(handler: Function) {
return (e: Object) => {
@@ -107,9 +107,11 @@ const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
function handleScroll(e: Object) {
e.persist();
e.stopPropagation();
// A scroll happened, so the scroll bumps the debounce.
const debouncedOnScrollEnd = debounce(handleScrollEnd, 100);
debouncedOnScrollEnd(e);
// A scroll happened, so the scroll resets the scrollend timeout.
if (scrollTimeout.current != null) {
clearTimeout(scrollTimeout.current);
}
scrollTimeout.current = setTimeout(handleScrollEnd, 100);
if (scrollState.current.isScrolling) {
// Scroll last tick may have changed, check if we need to notify
if (shouldEmitScrollEvent(scrollState.current.scrollLastTick, scrollEventThrottle)) {