Skip to content

Commit b6737d0

Browse files
authored
fix: Don't trigger press animation when sorting is disabled (#168)
## Description Small fix for incorrect press animation triggering. Animation is no longer triggered when sorting is not enabled on the sortable component.
1 parent 7552470 commit b6737d0

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/react-native-sortable/src/components/shared/DraggableView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react';
2-
import { type StyleProp, type ViewProps, type ViewStyle } from 'react-native';
2+
import type { StyleProp, ViewProps, ViewStyle } from 'react-native';
33
import { GestureDetector } from 'react-native-gesture-handler';
44
import Animated, {
55
useAnimatedRef,

packages/react-native-sortable/src/providers/shared/hooks/useItemPanGesture.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function useItemPanGesture(
1212
pressProgress: SharedValue<number>,
1313
reverseXAxis = false
1414
) {
15-
const { touchedItemKey } = useCommonValuesContext();
15+
const { sortEnabled, touchedItemKey } = useCommonValuesContext();
1616
const { handleDragEnd, handleTouchStart, handleTouchesMove } =
1717
useDragContext();
1818
const { updateStartScrollOffset } = useAutoScrollContext() ?? {};
@@ -23,7 +23,7 @@ export default function useItemPanGesture(
2323
.manualActivation(true)
2424
.onTouchesDown((e, manager) => {
2525
// Ignore touch if another item is already being touched/activated
26-
if (touchedItemKey.value !== null) {
26+
if (touchedItemKey.value !== null || !sortEnabled.value) {
2727
manager.fail();
2828
return;
2929
}
@@ -54,7 +54,8 @@ export default function useItemPanGesture(
5454
handleTouchStart,
5555
handleTouchesMove,
5656
handleDragEnd,
57-
updateStartScrollOffset
57+
updateStartScrollOffset,
58+
sortEnabled
5859
]
5960
);
6061
}

packages/react-native-sortable/tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"module": "esnext",
55
"noEmit": false,
66
"declaration": true,
7-
"target": "esnext"
7+
"target": "esnext",
8+
"types": ["react-native", "jest", "node"]
89
},
910
"include": ["src"],
1011
"exclude": ["__tests__", "**/*.test.ts", "**/*.test.tsx"]

0 commit comments

Comments
 (0)