|
1 | 1 | import { type ComponentType, useCallback } from 'react';
|
2 |
| -import { useAnimatedReaction, useSharedValue } from 'react-native-reanimated'; |
3 | 2 |
|
4 | 3 | import { useCommonValuesContext } from '../../providers';
|
5 | 4 | import type { AnyFunction, Maybe } from '../../types';
|
@@ -46,32 +45,15 @@ export default function createSortableTouchable<P extends AnyPressHandlers>(
|
46 | 45 | ): ComponentType<P> {
|
47 | 46 | function Wrapper({ onPress, ...rest }: P) {
|
48 | 47 | const { activationState } = useCommonValuesContext();
|
49 |
| - const isCancelled = useSharedValue(false); |
50 |
| - |
51 |
| - useAnimatedReaction( |
52 |
| - () => ({ |
53 |
| - dragState: activationState.value |
54 |
| - }), |
55 |
| - ({ dragState }) => { |
56 |
| - // Cancels when the item is active |
57 |
| - if (dragState === DragActivationState.ACTIVE) { |
58 |
| - isCancelled.value = true; |
59 |
| - } |
60 |
| - // Resets state when the item is touched again |
61 |
| - else if (dragState === DragActivationState.TOUCHED) { |
62 |
| - isCancelled.value = false; |
63 |
| - } |
64 |
| - } |
65 |
| - ); |
66 | 48 |
|
67 | 49 | const handlePress = useCallback(
|
68 | 50 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
69 | 51 | (...args: Array<any>) => {
|
70 |
| - if (isCancelled.value) return; |
| 52 | + if (activationState.value !== DragActivationState.INACTIVE) return; |
71 | 53 | // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
72 | 54 | onPress?.(...args);
|
73 | 55 | },
|
74 |
| - [isCancelled, onPress] |
| 56 | + [activationState, onPress] |
75 | 57 | );
|
76 | 58 |
|
77 | 59 | return <Component {...(rest as P)} onPress={handlePress} />;
|
|
0 commit comments