diff --git a/src/hooks/useOnCellActiveAnimation.ts b/src/hooks/useOnCellActiveAnimation.ts index 7c20587..e4cb304 100644 --- a/src/hooks/useOnCellActiveAnimation.ts +++ b/src/hooks/useOnCellActiveAnimation.ts @@ -1,6 +1,7 @@ -import { useRef } from "react"; +import { useEffect } from "react"; import Animated, { useDerivedValue, + useSharedValue, withSpring, WithSpringConfig, } from "react-native-reanimated"; @@ -15,8 +16,11 @@ type Params = { export function useOnCellActiveAnimation( { animationConfig }: Params = { animationConfig: {} } ) { - const animationConfigRef = useRef(animationConfig); - animationConfigRef.current = animationConfig; + const animationConfigRef = useSharedValue(animationConfig); + + useEffect(() => { + animationConfigRef.value = animationConfig; + }, [animationConfig]); const isActive = useIsActive(); @@ -26,8 +30,8 @@ export function useOnCellActiveAnimation( const toVal = isActive && isTouchActiveNative.value ? 1 : 0; return withSpring(toVal, { ...DEFAULT_ANIMATION_CONFIG, - ...animationConfigRef.current, - }); + ...animationConfigRef.value, + } as WithSpringConfig); }, [isActive]); return {