{"version":3,"names":["useHandler","useEvent","useAnimatedScrollHandler","handlers","dependencies","scrollHandlers","onScroll","context","doDependenciesDiffer","subscribeForEvents","onBeginDrag","undefined","push","onEndDrag","onMomentumBegin","onMomentumEnd","event","eventName","endsWith"],"sources":["useAnimatedScrollHandler.ts"],"sourcesContent":["'use strict';\nimport type {\n DependencyList,\n RNNativeScrollEvent,\n ReanimatedScrollEvent,\n} from './commonTypes';\nimport { useHandler } from './useHandler';\nimport type { EventHandlerInternal, EventHandlerProcessed } from './useEvent';\nimport { useEvent } from './useEvent';\n\nexport type ScrollHandler<\n Context extends Record = Record\n> = (event: ReanimatedScrollEvent, context: Context) => void;\nexport interface ScrollHandlers> {\n onScroll?: ScrollHandler;\n onBeginDrag?: ScrollHandler;\n onEndDrag?: ScrollHandler;\n onMomentumBegin?: ScrollHandler;\n onMomentumEnd?: ScrollHandler;\n}\n\nexport type ScrollHandlerProcessed<\n Context extends Record = Record\n> = EventHandlerProcessed;\n\nexport type ScrollHandlerInternal = EventHandlerInternal;\n\n/**\n * Lets you run callbacks on ScrollView events. Supports `onScroll`, `onBeginDrag`, `onEndDrag`, `onMomentumBegin`, and `onMomentumEnd` events.\n *\n * These callbacks are automatically workletized and ran on the UI thread.\n *\n * @param handlers - An object containing event handlers.\n * @param dependencies - An optional array of dependencies. Only relevant when using Reanimated without the Babel plugin on the Web.\n * @returns An object you need to pass to `onScroll` prop on the `Animated.ScrollView` component.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/scroll/useAnimatedScrollHandler\n */\n// @ts-expect-error This overload is required by our API.\nexport function useAnimatedScrollHandler<\n Context extends Record\n>(\n handlers: ScrollHandler | ScrollHandlers,\n dependencies?: DependencyList\n): ScrollHandlerProcessed;\n\nexport function useAnimatedScrollHandler<\n Context extends Record\n>(\n handlers: ScrollHandlers | ScrollHandler,\n dependencies?: DependencyList\n) {\n // case when handlers is a function\n const scrollHandlers: ScrollHandlers =\n typeof handlers === 'function' ? { onScroll: handlers } : handlers;\n const { context, doDependenciesDiffer } = useHandler<\n RNNativeScrollEvent,\n Context\n >(scrollHandlers as Record>, dependencies);\n\n // build event subscription array\n const subscribeForEvents = ['onScroll'];\n if (scrollHandlers.onBeginDrag !== undefined) {\n subscribeForEvents.push('onScrollBeginDrag');\n }\n if (scrollHandlers.onEndDrag !== undefined) {\n subscribeForEvents.push('onScrollEndDrag');\n }\n if (scrollHandlers.onMomentumBegin !== undefined) {\n subscribeForEvents.push('onMomentumScrollBegin');\n }\n if (scrollHandlers.onMomentumEnd !== undefined) {\n subscribeForEvents.push('onMomentumScrollEnd');\n }\n\n return useEvent(\n (event: ReanimatedScrollEvent) => {\n 'worklet';\n const {\n onScroll,\n onBeginDrag,\n onEndDrag,\n onMomentumBegin,\n onMomentumEnd,\n } = scrollHandlers;\n if (onScroll && event.eventName.endsWith('onScroll')) {\n onScroll(event, context);\n } else if (onBeginDrag && event.eventName.endsWith('onScrollBeginDrag')) {\n onBeginDrag(event, context);\n } else if (onEndDrag && event.eventName.endsWith('onScrollEndDrag')) {\n onEndDrag(event, context);\n } else if (\n onMomentumBegin &&\n event.eventName.endsWith('onMomentumScrollBegin')\n ) {\n onMomentumBegin(event, context);\n } else if (\n onMomentumEnd &&\n event.eventName.endsWith('onMomentumScrollEnd')\n ) {\n onMomentumEnd(event, context);\n }\n },\n subscribeForEvents,\n doDependenciesDiffer\n // Read https://github.com/software-mansion/react-native-reanimated/pull/5056\n // for more information about this cast.\n ) as unknown as ScrollHandlerInternal;\n}\n"],"mappings":"AAAA,YAAY;;AAMZ,SAASA,UAAU,QAAQ,cAAc;AAEzC,SAASC,QAAQ,QAAQ,YAAY;;AAmBrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GATA,CAUA;AAQA,OAAO,SAASC,wBAAwBA,CAGtCC,QAA0D,EAC1DC,YAA6B,EAC7B;EACA;EACA,MAAMC,cAAuC,GAC3C,OAAOF,QAAQ,KAAK,UAAU,GAAG;IAAEG,QAAQ,EAAEH;EAAS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