Skip to content

Commit

Permalink
Fix computerjazz#539: Tried to modify key current of an object.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCSmith committed Aug 20, 2024
1 parent 516a1a6 commit dc23035
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/DraggableFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
const springTo = placeholderOffset.value - activeCellOffset.value;
touchTranslate.value = withSpring(
springTo,
animationConfigRef.current,
animationConfigRef.value,
() => {
runOnJS(onDragEnd)({
from: activeIndexAnim.value,
Expand Down
8 changes: 4 additions & 4 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 { 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 @@ -54,8 +54,8 @@ function useSetupRefs<T>({
...DEFAULT_PROPS.animationConfig,
...animationConfig,
} as WithSpringConfig;
const animationConfigRef = useRef(animConfig);
animationConfigRef.current = animConfig;
const animationConfigRef = useSharedValue(animConfig);
animationConfigRef.value = animConfig;

const cellDataRef = useRef(new Map<string, CellData>());
const keyToIndexRef = useRef(new Map<string, number>());
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useCellTranslate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function useCellTranslate({ cellIndex, cellSize, cellOffset }: Params) {
? activeCellSize.value * (isAfterActive ? -1 : 1)
: 0;

return withSpring(translationAmt, animationConfigRef.current);
return withSpring(translationAmt, animationConfigRef.value);
}, [activeKey, cellIndex]);

return translate;
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useOnCellActiveAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef } from "react";
import Animated, {
useDerivedValue,
useSharedValue,
withSpring,
WithSpringConfig,
} from "react-native-reanimated";
Expand All @@ -15,8 +15,8 @@ type Params = {
export function useOnCellActiveAnimation(
{ animationConfig }: Params = { animationConfig: {} }
) {
const animationConfigRef = useRef(animationConfig);
animationConfigRef.current = animationConfig;
const animationConfigRef = useSharedValue(animationConfig);
animationConfigRef.value = animationConfig;

const isActive = useIsActive();

Expand All @@ -26,7 +26,7 @@ export function useOnCellActiveAnimation(
const toVal = isActive && isTouchActiveNative.value ? 1 : 0;
return withSpring(toVal, {
...DEFAULT_ANIMATION_CONFIG,
...animationConfigRef.current,
...animationConfigRef.value,
});
}, [isActive]);

Expand Down

0 comments on commit dc23035

Please sign in to comment.