import { createContext } from 'react'; import { makeMutable, type SharedValue, type WithSpringConfig, type WithTimingConfig, } from 'react-native-reanimated'; import { DefaultAnimationConfigs, DefaultPressableConfig, type DefaultPressableProps, type PressableConfig, } from './constants'; export type AnimationType = 'timing' | 'spring'; export type AnimatedPressableOptions = { isPressed: boolean; isToggled: boolean; isSelected: boolean; /** * Per-component metadata (falls back to the PressablesConfig metadata). * Useful inside globalHandlers to identify which pressable fired. * Optional: a pressable may not set it, so handlers should null-check. */ metadata?: TMetadata; }; export type PressableContextType< T extends AnimationType, TMetadata = unknown, > = { animationType: T; animationConfig: T extends 'timing' ? WithTimingConfig : WithSpringConfig; globalHandlers?: { onPressIn?: (options: AnimatedPressableOptions) => void; onPressOut?: (options: AnimatedPressableOptions) => void; onPress?: (options: AnimatedPressableOptions) => void; }; metadata?: TMetadata; /** * Activates the pressable animation on hover (web only) * @platform web */ activateOnHover?: boolean; /** * Pressable configuration values (opacity, scale, etc.) */ config: PressableConfig; /** * Default props applied to all pressables. * Individual pressable props will override these values. */ defaultProps?: DefaultPressableProps; }; export const PressablesContext = createContext< PressableContextType >({ animationType: 'timing', animationConfig: DefaultAnimationConfigs.timing, metadata: undefined, config: DefaultPressableConfig, }); export const PressablesGroupContext = createContext<{ lastTouchedPressable: SharedValue; }>({ lastTouchedPressable: makeMutable(null), });