Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
14 changes: 9 additions & 5 deletions src/hooks/useOnCellActiveAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRef } from "react";
import { useEffect } from "react";
import Animated, {
useDerivedValue,
useSharedValue,
withSpring,
WithSpringConfig,
} from "react-native-reanimated";
Expand All @@ -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();

Expand All @@ -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 {
Expand Down