Skip to content

Commit

Permalink
Update refContext.tsx
Browse files Browse the repository at this point in the history
[Reanimated] Tried to modify key `current` of an object which has been already passed to a worklet

computerjazz#539
  • Loading branch information
dmk3141618 authored Dec 5, 2024
1 parent 49bd1f3 commit 1c56e92
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/context/refContext.tsx
Original file line number Diff line number Diff line change
@@ -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<T> = {
propsRef: React.MutableRefObject<DraggableFlatListProps<T>>;
animationConfigRef: React.MutableRefObject<WithSpringConfig>;
animationConfigRef: SharedValue<WithSpringConfig>;
cellDataRef: React.MutableRefObject<Map<string, CellData>>;
keyToIndexRef: React.MutableRefObject<Map<string, number>>;
containerRef: React.RefObject<Animated.View>;
Expand Down Expand Up @@ -50,12 +50,18 @@ function useSetupRefs<T>({

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<string, CellData>());
const keyToIndexRef = useRef(new Map<string, number>());
Expand Down

0 comments on commit 1c56e92

Please sign in to comment.