import type { MotiPressableInteractionState } from './types' import { useAnimatedProps } from 'react-native-reanimated' import { MotiPressableInteractionIds, useMotiPressableContext } from './context' import { useFactory } from './use-validate-factory-or-id' type Factory = (interaction: MotiPressableInteractionState) => Props type Deps = unknown[] | null | undefined /** * Replacement for `useAnimatedProps`, which receives the interaction state as the first argument. * @param factory function that receives the interaction state and returns the props */ export function useMotiPressableAnimatedProps( id: MotiPressableInteractionIds['id'], factory: Factory, deps?: Deps ): Partial export function useMotiPressableAnimatedProps( factory: Factory, deps?: Deps ): Partial export function useMotiPressableAnimatedProps( factoryOrId: Factory | MotiPressableInteractionIds['id'], maybeFactoryOrDeps?: Factory | Deps, maybeDeps?: Deps ) { const context = useMotiPressableContext() const { factory, id, deps } = useFactory>( 'useMotiPressableAnimatedProps', factoryOrId, maybeFactoryOrDeps, maybeDeps ) return useAnimatedProps(() => { return context ? factory(context.containers[id].value) : {} }, deps) }