{"version":3,"names":["useRef","WorkletEventHandler","useEvent","handler","eventNames","arguments","length","undefined","rebuild","initRef","current","updateWorklet"],"sources":["useEvent.ts"],"sourcesContent":["'use strict';\nimport type { MutableRefObject } from 'react';\nimport { useRef } from 'react';\nimport WorkletEventHandler from '../WorkletEventHandler';\nimport type { ReanimatedEvent } from './commonTypes';\n\n/**\n * Worklet to provide as an argument to `useEvent` hook.\n */\nexport type EventHandler<\n Event extends object,\n Context extends Record = never\n> = (event: ReanimatedEvent, context?: Context) => void;\n\nexport type EventHandlerProcessed<\n Event extends object,\n Context extends Record = never\n> = (event: Event, context?: Context) => void;\n\nexport type EventHandlerInternal = MutableRefObject<\n WorkletEventHandler\n>;\n\n/**\n * Lets you run a function whenever a specified native event occurs.\n *\n * @param handler - A function that receives an event object with event data - {@link EventHandler}.\n * @param eventNames - An array of event names the `handler` callback will react to.\n * @param rebuild - Whether the event handler should be rebuilt. Defaults to `false`.\n * @returns A function that will be called when the event occurs - {@link EventHandlerProcessed}.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/advanced/useEvent\n */\n// @ts-expect-error This overload is required by our API.\n// We don't know which properites of a component that is made into\n// an AnimatedComponent are event handlers and we don't want to force the user to define it.\n// Therefore we disguise `useEvent` return type as a simple function and we handle\n// it being a React Ref in `createAnimatedComponent`.\nexport function useEvent<\n Event extends object,\n Context extends Record = never\n>(\n handler: EventHandler,\n eventNames?: string[],\n rebuild?: boolean\n): EventHandlerProcessed;\n\nexport function useEvent(\n handler: (event: ReanimatedEvent, context?: Context) => void,\n eventNames: string[] = [],\n rebuild = false\n): EventHandlerInternal {\n const initRef = useRef | null>(null);\n if (initRef.current === null) {\n initRef.current = new WorkletEventHandler(handler, eventNames);\n } else if (rebuild) {\n initRef.current.updateWorklet(handler);\n }\n\n // We cast it since we don't want to expose initial null value outside.\n return initRef as EventHandlerInternal;\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,MAAM,QAAQ,OAAO;AAC9B,OAAOC,mBAAmB,MAAM,wBAAwB;;AAGxD;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAUA,OAAO,SAASC,QAAQA,CACtBC,OAAmE,EAGtC;EAAA,IAF7BC,UAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAAA,IACzBG,OAAO,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAEf,MAAMI,OAAO,GAAGT,MAAM,CAAoC,IAAI,CAAC;EAC/D,IAAIS,OAAO,CAACC,OAAO,KAAK,IAAI,EAAE;IAC5BD,OAAO,CAACC,OAAO,GAAG,IAAIT,mBAAmB,CAAQE,OAAO,EAAEC,UAAU,CAAC;EACvE,CAAC,MAAM,IAAII,OAAO,EAAE;IAClBC,OAAO,CAACC,OAAO,CAACC,aAAa,CAACR,OAAO,CAAC;EACxC;;EAEA;EACA,OAAOM,OAAO;AAChB"}