import type { SharedValue } from 'react-native-reanimated'; import { useDerivedValue } from 'react-native-reanimated'; import { type MotiPressableInteractionIds, useMotiPressableContext } from './context'; import type { MotiPressableInteractionState } from './types'; import { useFactory } from './use-validate-factory-or-id'; type Factory = (interaction: MotiPressableInteractionState) => Props; type Deps = unknown[] | null | undefined; /** * Returns a Reanimated `SharedValue` that — unlike * `useMotiPressable`/`useMotiPressables` — holds the factory's **raw** * output rather than wrapping it as Moti `state`. * * Use this when you need a `SharedValue` that reacts to a * ``'s interaction state for custom worklet logic, rather * than driving a Moti component's `state` prop directly. * * @param id - Optional pressable `id` to target a specific ancestor. * @param factory - Called with `{ hovered, pressed }`; must return the * derived value. * @param deps - Optional dependency array. * @returns A readonly `SharedValue` that updates with the interaction. */ export function useInterpolateMotiPressable( id: MotiPressableInteractionIds['id'], factory: Factory, deps?: Deps, ): Readonly>; export function useInterpolateMotiPressable(factory: Factory, deps?: Deps): Readonly>; export function useInterpolateMotiPressable( factoryOrId: Factory | MotiPressableInteractionIds['id'], maybeFactoryOrDeps?: Factory | Deps, maybeDeps?: Deps, ): Readonly> { const context = useMotiPressableContext(); const { factory, id } = useFactory>('useMotiPressableAnimatedProps', factoryOrId, maybeFactoryOrDeps, maybeDeps); // RNR4: useDerivedValue no longer accepts a dependency array. return useDerivedValue(() => context && factory(context.containers[id]?.value ?? { hovered: false, pressed: false })); }