diff --git a/src/context/refContext.tsx b/src/context/refContext.tsx index ea21575c..1b7a287c 100644 --- a/src/context/refContext.tsx +++ b/src/context/refContext.tsx @@ -1,14 +1,14 @@ -import React, { useContext } from "react"; +import React, { useContext, useEffect } from "react"; import { useMemo, useRef } from "react"; import { FlatList } from "react-native-gesture-handler"; -import Animated, { WithSpringConfig } from "react-native-reanimated"; +import Animated, { type SharedValue, useSharedValue, WithSpringConfig } from "react-native-reanimated"; import { DEFAULT_PROPS } from "../constants"; import { useProps } from "./propsContext"; import { CellData, DraggableFlatListProps } from "../types"; type RefContextValue = { propsRef: React.MutableRefObject>; - animationConfigRef: React.MutableRefObject; + animationConfigRef: SharedValue; cellDataRef: React.MutableRefObject>; keyToIndexRef: React.MutableRefObject>; containerRef: React.RefObject; @@ -50,12 +50,18 @@ function useSetupRefs({ const propsRef = useRef(props); propsRef.current = props; - const animConfig = { - ...DEFAULT_PROPS.animationConfig, - ...animationConfig, - } as WithSpringConfig; - const animationConfigRef = useRef(animConfig); - animationConfigRef.current = animConfig; + const animConfig = useMemo( + () => ({ + ...DEFAULT_PROPS.animationConfig, + ...animationConfig, + } as WithSpringConfig), + [animationConfig] + ); + const animationConfigRef = useSharedValue(animConfig); + + useEffect(() => { + animationConfigRef.value = animConfig; + }, [animConfig]); const cellDataRef = useRef(new Map()); const keyToIndexRef = useRef(new Map());