UNPKG

repoweaver

Version:

A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies

1 lines 10.3 kB
{"ast":null,"code":"\"use strict\";\n\nimport { NavigationContext, useRoute } from '@react-navigation/core';\nimport * as React from 'react';\nfunction getScrollableNode(ref) {\n if (ref.current == null) {\n return null;\n }\n if ('scrollToTop' in ref.current || 'scrollTo' in ref.current || 'scrollToOffset' in ref.current || 'scrollResponderScrollTo' in ref.current) {\n return ref.current;\n } else if ('getScrollResponder' in ref.current) {\n return ref.current.getScrollResponder();\n } else if ('getNode' in ref.current) {\n return ref.current.getNode();\n } else {\n return ref.current;\n }\n}\nexport function useScrollToTop(ref) {\n var navigation = React.useContext(NavigationContext);\n var route = useRoute();\n if (navigation === undefined) {\n throw new Error(\"Couldn't find a navigation object. Is your component inside NavigationContainer?\");\n }\n React.useEffect(function () {\n var tabNavigations = [];\n var currentNavigation = navigation;\n while (currentNavigation) {\n if (currentNavigation.getState().type === 'tab') {\n tabNavigations.push(currentNavigation);\n }\n currentNavigation = currentNavigation.getParent();\n }\n if (tabNavigations.length === 0) {\n return;\n }\n var unsubscribers = tabNavigations.map(function (tab) {\n return tab.addListener('tabPress', function (e) {\n var isFocused = navigation.isFocused();\n var isFirst = tabNavigations.includes(navigation) || navigation.getState().routes[0].key === route.key;\n requestAnimationFrame(function () {\n var scrollable = getScrollableNode(ref);\n if (isFocused && isFirst && scrollable && !e.defaultPrevented) {\n if ('scrollToTop' in scrollable) {\n scrollable.scrollToTop();\n } else if ('scrollTo' in scrollable) {\n scrollable.scrollTo({\n y: 0,\n animated: true\n });\n } else if ('scrollToOffset' in scrollable) {\n scrollable.scrollToOffset({\n offset: 0,\n animated: true\n });\n } else if ('scrollResponderScrollTo' in scrollable) {\n scrollable.scrollResponderScrollTo({\n y: 0,\n animated: true\n });\n }\n }\n });\n });\n });\n return function () {\n unsubscribers.forEach(function (unsubscribe) {\n return unsubscribe();\n });\n };\n }, [navigation, ref, route.key]);\n}","map":{"version":3,"names":["NavigationContext","useRoute","React","getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","useContext","route","undefined","Error","useEffect","tabNavigations","currentNavigation","getState","type","push","getParent","length","unsubscribers","map","tab","addListener","e","isFocused","isFirst","includes","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo","forEach","unsubscribe"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/native/src/useScrollToTop.tsx"],"sourcesContent":["import {\n type EventArg,\n NavigationContext,\n type NavigationProp,\n type ParamListBase,\n useRoute,\n} from '@react-navigation/core';\nimport * as React from 'react';\nimport type { ScrollView } from 'react-native';\n\ntype ScrollOptions = { x?: number; 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 | ScrollView }\n | { getNode(): ScrollableView }\n | ScrollableView\n | null;\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 wrapped 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 }\n}\n\nexport function useScrollToTop(ref: React.RefObject<ScrollableWrapper>) {\n const navigation = React.useContext(NavigationContext);\n const route = useRoute();\n\n if (navigation === undefined) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n React.useEffect(() => {\n const tabNavigations: NavigationProp<ParamListBase>[] = [];\n let currentNavigation = navigation;\n // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them\n // So we need to find all the parent tab navigators and add the listeners there\n while (currentNavigation) {\n if (currentNavigation.getState().type === 'tab') {\n tabNavigations.push(currentNavigation);\n }\n\n currentNavigation = currentNavigation.getParent();\n }\n\n if (tabNavigations.length === 0) {\n return;\n }\n\n const unsubscribers = tabNavigations.map((tab) => {\n return tab.addListener(\n // We don't wanna import tab types here to avoid extra deps\n // in addition, there are multiple tab implementations\n // @ts-expect-error the `tabPress` event is only available when navigation type is tab\n 'tabPress',\n (e: EventArg<'tabPress', true>) => {\n // We should scroll to top only when the screen is focused\n const isFocused = navigation.isFocused();\n\n // In a nested stack navigator, tab press resets the stack to first screen\n // So we should scroll to top only when we are on first screen\n const isFirst =\n tabNavigations.includes(navigation) ||\n navigation.getState().routes[0].key === route.key;\n\n // Run the operation in the next frame so we're sure all listeners have been run\n // This is necessary to know if preventDefault() has been called\n requestAnimationFrame(() => {\n const scrollable = getScrollableNode(ref) as ScrollableWrapper;\n\n if (isFocused && isFirst && scrollable && !e.defaultPrevented) {\n if ('scrollToTop' in scrollable) {\n scrollable.scrollToTop();\n } else if ('scrollTo' in scrollable) {\n scrollable.scrollTo({ y: 0, animated: true });\n } else if ('scrollToOffset' in scrollable) {\n scrollable.scrollToOffset({ offset: 0, animated: true });\n } else if ('scrollResponderScrollTo' in scrollable) {\n scrollable.scrollResponderScrollTo({ y: 0, animated: true });\n }\n }\n });\n }\n );\n });\n\n return () => {\n unsubscribers.forEach((unsubscribe) => unsubscribe());\n };\n }, [navigation, ref, route.key]);\n}\n"],"mappings":";;AAAA,SAEEA,iBAAiB,EAGjBC,QAAQ,QACH,wBAAwB;AAC/B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