Skip to content

Commit 76078df

Browse files
authored
Merge branch 'next' into @akwasniewski/native-gesture-web
2 parents c2e577a + 16d9071 commit 76078df

File tree

10 files changed

+25
-59
lines changed

10 files changed

+25
-59
lines changed

apps/basic-example/src/NativeDetector.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export default function App() {
1818
);
1919

2020
const gesture = useGesture('PanGestureHandler', {
21-
onGestureHandlerAnimatedEvent: event,
22-
onGestureHandlerEvent: (e: any) =>
23-
console.log('onGestureHandlerEvent', e.nativeEvent),
21+
onUpdate: event,
2422
});
2523

2624
return (

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
1414
private var handlersToAttach: List<Int>? = null
1515
private var attachedHandlers = listOf<Int>()
1616
private var moduleId: Int = -1
17-
private var dispatchesAnimatedEvents: Boolean = false
1817

1918
fun setHandlerTags(handlerTags: ReadableArray?) {
2019
val newHandlers = handlerTags?.toArrayList()?.map { (it as Double).toInt() } ?: emptyList()
@@ -36,10 +35,6 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
3635
handlersToAttach = null
3736
}
3837

39-
fun setDispatchesAnimatedEvents(dispatchesAnimatedEvents: Boolean) {
40-
this.dispatchesAnimatedEvents = dispatchesAnimatedEvents
41-
}
42-
4338
private fun attachHandlers(newHandlers: List<Int>) {
4439
val registry = RNGestureHandlerModule.registries[moduleId]
4540
?: throw Exception("Tried to access a non-existent registry")

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorViewManager.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,4 @@ class RNGestureHandlerDetectorViewManager :
3636
override fun setModuleId(view: RNGestureHandlerDetectorView, value: Int) {
3737
view.setModuleId(value)
3838
}
39-
40-
override fun setDispatchesAnimatedEvents(view: RNGestureHandlerDetectorView, value: Boolean) {
41-
view.setDispatchesAnimatedEvents(value)
42-
}
4339
}

packages/react-native-gesture-handler/src/specs/RNGestureHandlerDetectorNativeComponent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export interface NativeProps extends ViewProps {
4949
onGestureHandlerTouchEvent?: DirectEventHandler<GestureHandlerTouchEvent>;
5050

5151
handlerTags: Int32[];
52-
dispatchesAnimatedEvents: boolean;
5352
moduleId: Int32;
5453
}
5554

packages/react-native-gesture-handler/src/v3/NativeDetector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ const ReanimatedNativeDetector =
1818
Reanimated?.default.createAnimatedComponent(HostGestureDetector);
1919

2020
export function NativeDetector({ gesture, children }: NativeDetectorProps) {
21-
const NativeDetectorComponent = gesture.dispatchesAnimatedEvents
21+
const NativeDetectorComponent = gesture.config.dispatchesAnimatedEvents
2222
? AnimatedNativeDetector
23-
: gesture.shouldUseReanimated
23+
: // TODO: Remove this cast when we properly type config
24+
(gesture.config.shouldUseReanimated as boolean)
2425
? ReanimatedNativeDetector
2526
: HostGestureDetector;
2627

@@ -45,7 +46,6 @@ export function NativeDetector({ gesture, children }: NativeDetectorProps) {
4546
onGestureHandlerTouchEvent={
4647
gesture.gestureEvents.onGestureHandlerTouchEvent
4748
}
48-
dispatchesAnimatedEvents={gesture.dispatchesAnimatedEvents}
4949
moduleId={globalThis._RNGH_MODULE_ID}
5050
handlerTags={[gesture.tag]}
5151
style={styles.detector}>

packages/react-native-gesture-handler/src/v3/hooks/events/useGestureHandlerEvent.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import {
1111
import { CallbackHandlers, UpdateEvent } from '../../types';
1212
import { tagMessage } from '../../../utils';
1313

14-
export function useGestureHandlerEvent(
15-
handlerTag: number,
16-
config: any,
17-
shouldUseReanimated: boolean
18-
) {
14+
export function useGestureHandlerEvent(handlerTag: number, config: any) {
1915
const handlers: CallbackHandlers = {
2016
onUpdate: config.onUpdate,
2117
};
@@ -73,7 +69,7 @@ export function useGestureHandlerEvent(
7369

7470
return isAnimatedEvent(config.onUpdate)
7571
? undefined
76-
: shouldUseReanimated
72+
: config.shouldUseReanimated
7773
? reanimatedEvent
7874
: (event: UpdateEvent<Record<string, unknown>>) =>
7975
onGestureHandlerEvent(event, jsContext);

packages/react-native-gesture-handler/src/v3/hooks/events/useGestureStateChangeEvent.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import { State } from '../../../State';
88
import { Reanimated } from '../../../handlers/gestures/reanimatedWrapper';
99
import { CallbackHandlers, StateChangeEvent } from '../../types';
1010

11-
export function useGestureStateChangeEvent(
12-
handlerTag: number,
13-
config: any,
14-
shouldUseReanimated: boolean
15-
) {
11+
export function useGestureStateChangeEvent(handlerTag: number, config: any) {
1612
const handlers: CallbackHandlers = {
1713
onBegin: config.onBegin,
1814
onStart: config.onStart,
@@ -76,5 +72,7 @@ export function useGestureStateChangeEvent(
7672
!!reanimatedHandler?.doDependenciesDiffer
7773
);
7874

79-
return shouldUseReanimated ? reanimatedEvent : onGestureHandlerStateChange;
75+
return config.shouldUseReanimated
76+
? reanimatedEvent
77+
: onGestureHandlerStateChange;
8078
}

packages/react-native-gesture-handler/src/v3/hooks/events/useTouchEvent.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import { TouchEventType } from '../../../TouchEventType';
1010
import { CallbackHandlers, TouchEvent } from '../../types';
1111
import { NativeSyntheticEvent } from 'react-native';
1212

13-
export function useTouchEvent(
14-
handlerTag: number,
15-
config: any,
16-
shouldUseReanimated: boolean
17-
) {
13+
export function useTouchEvent(handlerTag: number, config: any) {
1814
const handlers: CallbackHandlers = {
1915
onTouchesDown: config.onTouchesDown,
2016
onTouchesMove: config.onTouchesMove,
@@ -65,5 +61,7 @@ export function useTouchEvent(
6561
!!reanimatedHandler?.doDependenciesDiffer
6662
);
6763

68-
return shouldUseReanimated ? reanimatedEvent : onGestureHandlerTouchEvent;
64+
return config.shouldUseReanimated
65+
? reanimatedEvent
66+
: onGestureHandlerTouchEvent;
6967
}

packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export interface NativeGesture {
2929
name: GestureType;
3030
config: Record<string, unknown>;
3131
gestureEvents: GestureEvents;
32-
shouldUseReanimated: boolean;
33-
dispatchesAnimatedEvents: boolean;
3432
}
3533

3634
function hasWorkletEventHandlers(config: Record<string, unknown>) {
@@ -63,7 +61,8 @@ export function useGesture(
6361
);
6462
}
6563

66-
const shouldUseReanimated =
64+
// This has to be done ASAP as other hooks depend `shouldUseReanimated`.
65+
config.shouldUseReanimated =
6766
Reanimated !== undefined && hasWorkletEventHandlers(config);
6867
config.needsPointerData = shouldHandleTouchEvents(config);
6968

@@ -72,7 +71,7 @@ export function useGesture(
7271
onGestureHandlerEvent,
7372
onGestureHandlerAnimatedEvent,
7473
onGestureHandlerTouchEvent,
75-
} = useGestureEvent(tag, config, shouldUseReanimated);
74+
} = useGestureEvent(tag, config);
7675

7776
// This should never happen, but since we don't want to call hooks conditionally,
7877
// we have to mark these as possibly undefined to make TypeScript happy.
@@ -85,6 +84,10 @@ export function useGesture(
8584
throw new Error(tagMessage('Failed to create event handlers.'));
8685
}
8786

87+
config.dispatchesAnimatedEvents =
88+
!!onGestureHandlerAnimatedEvent &&
89+
'__isNative' in onGestureHandlerAnimatedEvent;
90+
8891
useMemo(() => {
8992
RNGestureHandlerModule.createGestureHandler(type, tag, {});
9093
RNGestureHandlerModule.flushOperations();
@@ -118,9 +121,5 @@ export function useGesture(
118121
onGestureHandlerTouchEvent,
119122
onGestureHandlerAnimatedEvent,
120123
},
121-
shouldUseReanimated,
122-
dispatchesAnimatedEvents:
123-
!!onGestureHandlerAnimatedEvent &&
124-
'__isNative' in onGestureHandlerAnimatedEvent,
125124
};
126125
}

packages/react-native-gesture-handler/src/v3/hooks/useGestureEvent.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,14 @@ import { useTouchEvent } from './events/useTouchEvent';
44
import { AnimatedEvent } from '../types';
55
import { checkMappingForChangeProperties, isAnimatedEvent } from './utils';
66

7-
export function useGestureEvent(
8-
handlerTag: number,
9-
config: any,
10-
shouldUseReanimated: boolean
11-
) {
7+
export function useGestureEvent(handlerTag: number, config: any) {
128
const onGestureHandlerStateChange = useGestureStateChangeEvent(
139
handlerTag,
14-
config,
15-
shouldUseReanimated
16-
);
17-
const onGestureHandlerEvent = useGestureHandlerEvent(
18-
handlerTag,
19-
config,
20-
shouldUseReanimated
10+
config
2111
);
12+
const onGestureHandlerEvent = useGestureHandlerEvent(handlerTag, config);
2213

23-
const onGestureHandlerTouchEvent = useTouchEvent(
24-
handlerTag,
25-
config,
26-
shouldUseReanimated
27-
);
14+
const onGestureHandlerTouchEvent = useTouchEvent(handlerTag, config);
2815

2916
let onGestureHandlerAnimatedEvent: AnimatedEvent | undefined;
3017

0 commit comments

Comments
 (0)