Skip to content

Commit 2a1d8a7

Browse files
committed
Merge branch '@akwasniewski/native-detector-web' into @akwasniewski/native-gesture-web
2 parents c2e577a + 38b240a commit 2a1d8a7

19 files changed

+76
-112
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/RNGestureHandlerModule.web.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ export default {
4848
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4949
newView: any,
5050
actionType: ActionType,
51-
propsRef: React.RefObject<PropsRef>,
52-
forAnimated: boolean
51+
propsRef: React.RefObject<PropsRef>
5352
) {
5453
if (!(newView instanceof Element || newView instanceof React.Component)) {
5554
shouldPreventDrop = true;
@@ -64,12 +63,7 @@ export default {
6463
}
6564

6665
// @ts-ignore Types should be HTMLElement or React.Component
67-
NodeManager.getHandler(handlerTag).init(
68-
newView,
69-
propsRef,
70-
actionType,
71-
forAnimated
72-
);
66+
NodeManager.getHandler(handlerTag).init(newView, propsRef, actionType);
7367
},
7468
detachGestureHandler(handlerTag: number) {
7569
if (shouldPreventDrop) {

packages/react-native-gesture-handler/src/handlers/createHandler.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ type AttachGestureHandlerWeb = (
160160
// eslint-disable-next-line @typescript-eslint/no-explicit-any
161161
newView: any,
162162
_actionType: ActionType,
163-
propsRef: React.RefObject<unknown>,
164-
forAnimated: boolean
163+
propsRef: React.RefObject<unknown>
165164
) => void;
166165

167166
const UNRESOLVED_REFS_RETRY_LIMIT = 1;
@@ -350,8 +349,7 @@ export default function createHandler<
350349
this.handlerTag,
351350
newViewTag,
352351
ActionType.JS_FUNCTION_OLD_API, // ignored on web
353-
this.propsRef,
354-
false
352+
this.propsRef
355353
);
356354
} else {
357355
registerOldGestureHandler(this.handlerTag, {

packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/attachHandlers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ export function attachHandlers({
8686
gesture.handlerTag,
8787
viewTag,
8888
ActionType.JS_FUNCTION_OLD_API, // Ignored on web
89-
webEventHandlersRef,
90-
false
89+
webEventHandlersRef
9190
);
9291
} else {
9392
RNGestureHandlerModule.attachGestureHandler(

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/HostGestureDetector.web.tsx

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import { Wrap } from '../handlers/gestures/GestureDetector/Wrap';
77

88
export interface GestureHandlerDetectorProps extends PropsRef {
99
handlerTags: number[];
10-
dispatchesAnimatedEvents: boolean;
1110
moduleId: number;
1211
children?: React.ReactNode;
1312
}
1413

1514
const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
16-
const { handlerTags, dispatchesAnimatedEvents, children } = props;
15+
const { handlerTags, children } = props;
1716

1817
const viewRef = useRef(null);
1918
const childRef = useRef(null);
@@ -35,36 +34,32 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
3534
});
3635
}, []);
3736

38-
const attachHandlers = useCallback(
39-
(currentHandlerTags: Set<number>) => {
40-
const oldHandlerTags =
41-
attachedHandlerTags.current.difference(currentHandlerTags);
42-
const newHandlerTags = currentHandlerTags.difference(
43-
attachedHandlerTags.current
44-
);
37+
const attachHandlers = useCallback((currentHandlerTags: Set<number>) => {
38+
const oldHandlerTags =
39+
attachedHandlerTags.current.difference(currentHandlerTags);
40+
const newHandlerTags = currentHandlerTags.difference(
41+
attachedHandlerTags.current
42+
);
4543

46-
detachHandlers(oldHandlerTags);
44+
detachHandlers(oldHandlerTags);
4745

48-
newHandlerTags.forEach((tag) => {
49-
const attachTarget = shouldAttachGestureToChildView(tag)
50-
? childRef.current
51-
: viewRef.current;
52-
RNGestureHandlerModule.attachGestureHandler(
53-
tag,
54-
attachTarget,
55-
ActionType.NATIVE_DETECTOR,
56-
propsRef,
57-
dispatchesAnimatedEvents
58-
);
59-
});
60-
attachedHandlerTags.current = currentHandlerTags;
61-
},
62-
[dispatchesAnimatedEvents]
63-
);
46+
newHandlerTags.forEach((tag) => {
47+
const attachTarget = shouldAttachGestureToChildView(tag)
48+
? childRef.current
49+
: viewRef.current;
50+
RNGestureHandlerModule.attachGestureHandler(
51+
tag,
52+
attachTarget,
53+
ActionType.NATIVE_DETECTOR,
54+
propsRef
55+
);
56+
});
57+
attachedHandlerTags.current = currentHandlerTags;
58+
}, []);
6459

6560
useEffect(() => {
6661
attachHandlers(new Set(handlerTags));
67-
}, [attachHandlers]);
62+
}, [handlerTags]);
6863

6964
useEffect(() => {
7065
return () => {

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);

0 commit comments

Comments
 (0)