From b7714522147ff627b713df9a994266e724b9c9b0 Mon Sep 17 00:00:00 2001 From: Justin Jaeger Date: Sun, 5 May 2024 19:00:43 -0400 Subject: [PATCH] fix: bad initial scrollInit value causes auto-scroll when drag begins --- src/components/DraggableFlatList.tsx | 2 ++ src/context/animatedValueContext.tsx | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/DraggableFlatList.tsx b/src/components/DraggableFlatList.tsx index d7d98c27..a802e370 100644 --- a/src/components/DraggableFlatList.tsx +++ b/src/components/DraggableFlatList.tsx @@ -65,6 +65,7 @@ function DraggableFlatListInner(props: DraggableFlatListProps) { activeCellSize, activeIndexAnim, containerSize, + scrollInit, scrollOffset, scrollViewSize, spacerIndexAnim, @@ -85,6 +86,7 @@ function DraggableFlatListInner(props: DraggableFlatListProps) { touchTranslate.value = 0; activeCellSize.value = -1; activeCellOffset.value = -1; + scrollInit.value = -1; setActiveKey(null); }); diff --git a/src/context/animatedValueContext.tsx b/src/context/animatedValueContext.tsx index 6ff1ed5f..4f57fd5d 100644 --- a/src/context/animatedValueContext.tsx +++ b/src/context/animatedValueContext.tsx @@ -61,7 +61,7 @@ function useSetupAnimatedValues() { const activeCellOffset = useSharedValue(0); // Distance between active cell and edge of container const scrollOffset = useSharedValue(0); - const scrollInit = useSharedValue(0); + const scrollInit = useSharedValue(-1); const viewableIndexMin = useSharedValue(0); const viewableIndexMax = useSharedValue(0); @@ -90,7 +90,8 @@ function useSetupAnimatedValues() { }, []); const autoScrollDistance = useDerivedValue(() => { - if (!isDraggingCell.value) return 0; + const scrollInitIsNotSet = scrollInit.value === -1; + if (!isDraggingCell.value || scrollInitIsNotSet) return 0; const innerScrollDiff = scrollOffset.value - scrollInit.value; // If list is nested there may be an outer scroll diff const outerScrollDiff = outerScrollOffset.value - outerScrollInit.value; @@ -173,6 +174,7 @@ function useSetupAnimatedValues() { panGestureState, placeholderOffset, resetTouchedCell, + scrollInit, scrollOffset, scrollViewSize, spacerIndexAnim, @@ -196,6 +198,7 @@ function useSetupAnimatedValues() { panGestureState, placeholderOffset, resetTouchedCell, + scrollInit, scrollOffset, scrollViewSize, spacerIndexAnim,