@@ -9,30 +9,31 @@ type ScrollableView =
99 | { scrollToOffset ( options : ScrollOptions ) : void }
1010 | { scrollResponderScrollTo ( options : ScrollOptions ) : void } ;
1111
12- type MaybeScrollableWrapperView =
13- | ScrollableView
14- | { getScrollResponder : ( ) => ScrollableView }
15- | { getNode : ( ) => ScrollableView } ;
12+ type ScrollableWrapper =
13+ | { getScrollResponder ( ) : ScrollableView }
14+ | { getNode ( ) : ScrollableView }
15+ | ScrollableView ;
1616
17- function getNodeFromRef (
18- ref : React . RefObject < MaybeScrollableWrapperView >
19- ) : ScrollableView | null {
20- if ( ref . current === null ) {
17+ function getScrollableNode ( ref : React . RefObject < ScrollableWrapper > ) {
18+ if ( ref . current == null ) {
2119 return null ;
2220 }
2321
24- // Support weird animated containers and Animated components.
2522 if ( 'getScrollResponder' in ref . current ) {
23+ // If the view is a wrapper like FlatList, SectionList etc.
24+ // We need to use `getScrollResponder` to get access to the scroll responder
2625 return ref . current . getScrollResponder ( ) ;
2726 } else if ( 'getNode' in ref . current ) {
27+ // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
28+ // we need to use `getNode` to get the ref to the actual scrollview
2829 return ref . current . getNode ( ) ;
2930 } else {
3031 return ref . current ;
3132 }
3233}
3334
3435export default function useScrollToTop (
35- ref : React . RefObject < MaybeScrollableWrapperView >
36+ ref : React . RefObject < ScrollableWrapper >
3637) {
3738 const navigation = useNavigation ( ) ;
3839
@@ -47,7 +48,7 @@ export default function useScrollToTop(
4748 // Run the operation in the next frame so we're sure all listeners have been run
4849 // This is necessary to know if preventDefault() has been called
4950 requestAnimationFrame ( ( ) => {
50- const scrollable = getNodeFromRef ( ref ) ;
51+ const scrollable = getScrollableNode ( ref ) ;
5152
5253 if ( isFocused && ! e . defaultPrevented && scrollable ) {
5354 // When user taps on already focused tab, scroll to top
0 commit comments