Skip to content

Commit

Permalink
Apply patches from computerjazz#539
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottkember committed Sep 6, 2024
1 parent 3061e30 commit 28736f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 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
11 changes: 6 additions & 5 deletions src/hooks/useOnCellActiveAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useRef } from "react";
import Animated, {

import {
useDerivedValue,
withSpring,
WithSpringConfig,
useSharedValue,
} from "react-native-reanimated";
import { DEFAULT_ANIMATION_CONFIG } from "../constants";
import { useAnimatedValues } from "../context/animatedValueContext";
Expand All @@ -15,8 +16,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 +27,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 28736f7

Please sign in to comment.