1 line
6.1 KiB
Plaintext
1 line
6.1 KiB
Plaintext
|
{"version":3,"sources":["useScrollToTop.tsx"],"names":["React","useNavigation","useRoute","getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","route","useEffect","dangerouslyGetState","type","dangerouslyGetParent","unsubscribe","addListener","e","isFocused","isFirst","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,aAAT,EAAwBC,QAAxB,QAAkD,wBAAlD;;AAeA,SAASC,iBAAT,CAA2BC,GAA3B,EAAoE;AAClE,MAAIA,GAAG,CAACC,OAAJ,IAAe,IAAnB,EAAyB;AACvB,WAAO,IAAP;AACD;;AAED,MACE,iBAAiBD,GAAG,CAACC,OAArB,IACA,cAAcD,GAAG,CAACC,OADlB,IAEA,oBAAoBD,GAAG,CAACC,OAFxB,IAGA,6BAA6BD,GAAG,CAACC,OAJnC,EAKE;AACA;AACA,WAAOD,GAAG,CAACC,OAAX;AACD,GARD,MAQO,IAAI,wBAAwBD,GAAG,CAACC,OAAhC,EAAyC;AAC9C;AACA;AACA,WAAOD,GAAG,CAACC,OAAJ,CAAYC,kBAAZ,EAAP;AACD,GAJM,MAIA,IAAI,aAAaF,GAAG,CAACC,OAArB,EAA8B;AACnC;AACA;AACA;AACA;AACA,WAAOD,GAAG,CAACC,OAAJ,CAAYE,OAAZ,EAAP;AACD,GANM,MAMA;AACL,WAAOH,GAAG,CAACC,OAAX;AACD;AACF;;AAED,eAAe,SAASG,cAAT,CACbJ,GADa,EAEb;AACA,QAAMK,UAAU,GAAGR,aAAa,EAAhC;AACA,QAAMS,KAAK,GAAGR,QAAQ,EAAtB;AAEAF,EAAAA,KAAK,CAACW,SAAN,CAAgB,MAAM;AACpB,QAAIN,OAAO,GAAGI,UAAd,CADoB,CAGpB;AACA;;AACA,WAAOJ,OAAO,IAAIA,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;AACF,OAdoB,CAArB;AAeD,KAhCiB,CAApB;AAmCA,WAAOb,WAAP;AACD,GAjDD,EAiDG,CAACN,UAAD,EAAaL,GAAb,EAAkBM,KAAK,CAACW,GAAxB,CAjDH;AAkDD","sourcesContent":["import * as React from 'react';\nimport { useNavigation, useRoute, EventArg } from '@react-navigation/core';\n\ntype ScrollOptions = { y?: number; animated?: boolean };\n\ntype ScrollableView =\n | { scrollToTop(): void }\n | { scrollTo(options: ScrollOptions): void }\n | { scrollToOffset(options: { offset?: number; animated?: boolean }): void }\n | { scrollResponderScrollTo(options: ScrollOptions): void };\n\ntype ScrollableWrapper =\n | { getScrollResponder(): React.ReactNode }\n | { getNode(): ScrollableView }\n | ScrollableView;\n\nfunction getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {\n if (ref.current == null) {\n return null;\n }\n\n if (\n 'scrollToTop' in ref.current ||\n 'scrollTo' in ref.current ||\n 'scrollToOffset' in ref.current ||\n 'scrollResponderScrollTo' in ref.current\n ) {\n // This is already a scrollable node.\n return ref.current;\n } else if ('getScrollResponder' in ref.current) {\n // If the view is a wrapper like FlatList, SectionList etc.\n // We need to use `getScrollResponder` to get access to the scroll responder\n return ref.current.getScrollResponder();\n } else if ('getNode' in ref.current) {\n // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`\n // we need to use `getNode` to get the ref to the actual scrollview.\n // Note that `getNode` is deprecated in newer versions of react-native\n // this is why we check if we already have a scrollable node above.\n return ref.current.getNode();\n } else {\n return ref.current;\n }\
|