import { useRef } from 'react' import Animated, { useSharedValue } from 'react-native-reanimated' type InternalControllerState = number | V[keyof V] type Controller = { /** * A hook to synchronously read the current animation state. * * ```js * const animator = useAnimator({ * hidden: { opacity: 0 }, * shown: { opacity: 1 } * }) * * const onPress = () => { * if (animator.current === 'hidden') { * animator.transitionTo('shown') * } else { * animator.transitionTo('hidden') * } * } * ``` * * Do not mutate the `current` value directly; this will break. Instead, use the `transitionTo` function. */ current: null | keyof V /** * @private * Internal state used to drive animations. You shouldn't use this. Use `.current` instead to read the current state. Use `transitionTo` to edit it. */ __state: Animated.SharedValue /** * Transition to another state, as defined by this hook. * * ```js * const animator = useAnimator({ * hidden: { opacity: 0 }, * shown: { opacity: 1 } * }) * * const onPress = () => { * if (animator.current === 'hidden') { * animator.transitionTo('shown') * } else { * animator.transitionTo('hidden') * } * } * ``` */ transitionTo: (key: keyof V | ((currentState: keyof V) => keyof V)) => void } /** * * `useAnimatedState` lets you control your animation state, based on static presets. It is the most performant way to drive animations. * * @param variants specify your style variants. * @param config Optionally define your from variant key. * * **Example** * * ```jsx * const animator = useAnimatedState({ * from: { * opacity: 0 * }, * open: { * opacity: 1 * }, * pressed: { * opacity: 0.7 * } * }) * * return ( * <> * *