@@ -13,6 +13,7 @@ import * as React from 'react';
13
13
import { forwardRef , useRef } from 'react' ;
14
14
import StyleSheet from '../StyleSheet' ;
15
15
import View from '../View' ;
16
+ import useMergeRefs from '../../modules/useMergeRefs' ;
16
17
17
18
type Props = {
18
19
...ViewProps ,
@@ -93,6 +94,7 @@ const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
93
94
94
95
const scrollState = useRef ( { isScrolling : false , scrollLastTick : 0 } ) ;
95
96
const scrollTimeout = useRef ( null ) ;
97
+ const scrollRef = useRef ( null ) ;
96
98
97
99
function createPreventableScrollHandler ( handler : Function ) {
98
100
return ( e : Object ) => {
@@ -105,29 +107,31 @@ const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
105
107
}
106
108
107
109
function handleScroll ( e : Object ) {
108
- e . persist ( ) ;
109
110
e . stopPropagation ( ) ;
110
- // A scroll happened, so the scroll resets the scrollend timeout.
111
- if ( scrollTimeout . current != null ) {
112
- clearTimeout ( scrollTimeout . current ) ;
113
- }
114
- scrollTimeout . current = setTimeout ( ( ) => {
115
- handleScrollEnd ( e ) ;
116
- } , 100 ) ;
117
- if ( scrollState . current . isScrolling ) {
118
- // Scroll last tick may have changed, check if we need to notify
119
- if ( shouldEmitScrollEvent ( scrollState . current . scrollLastTick , scrollEventThrottle ) ) {
120
- handleScrollTick ( e ) ;
111
+ if ( e . target === scrollRef . current ) {
112
+ e . persist ( ) ;
113
+ // A scroll happened, so the scroll resets the scrollend timeout.
114
+ if ( scrollTimeout . current != null ) {
115
+ clearTimeout ( scrollTimeout . current ) ;
116
+ }
117
+ scrollTimeout . current = setTimeout ( ( ) => {
118
+ handleScrollEnd ( e ) ;
119
+ } , 100 ) ;
120
+ if ( scrollState . current . isScrolling ) {
121
+ // Scroll last tick may have changed, check if we need to notify
122
+ if ( shouldEmitScrollEvent ( scrollState . current . scrollLastTick , scrollEventThrottle ) ) {
123
+ handleScrollTick ( e ) ;
124
+ }
125
+ } else {
126
+ // Weren't scrolling, so we must have just started
127
+ handleScrollStart ( e ) ;
121
128
}
122
- } else {
123
- // Weren't scrolling, so we must have just started
124
- handleScrollStart ( e ) ;
125
129
}
126
130
}
127
131
128
132
function handleScrollStart ( e : Object ) {
129
133
scrollState . current . isScrolling = true ;
130
- scrollState . current . scrollLastTick = Date . now ( ) ;
134
+ handleScrollTick ( e ) ;
131
135
}
132
136
133
137
function handleScrollTick ( e : Object ) {
@@ -161,7 +165,7 @@ const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
161
165
onTouchMove = { createPreventableScrollHandler ( onTouchMove ) }
162
166
onWheel = { createPreventableScrollHandler ( onWheel ) }
163
167
pointerEvents = { pointerEvents }
164
- ref = { forwardedRef }
168
+ ref = { useMergeRefs ( scrollRef , forwardedRef ) }
165
169
style = { [
166
170
style ,
167
171
! scrollEnabled && styles . scrollDisabled ,
0 commit comments