Skip to content

Commit f30ba2a

Browse files
authored
Decouple the JS implementation from the web APIs (#2579)
## Description - adds a `GestureHandlerDelegate` interface to encapsulate web-specific calls from the js implementation - makes `EventManager` generic so it doesn't rely on web types - in some places adds `Platform.OS` checks, when there is the need to manipulate the underlying `HTMLElement` It could still be beneficial to pass the ref to the js implementation instead of the node handle (which is the same thing on the web, but not on other platforms). ## Test plan Tested on the example app.
1 parent c9cdc1f commit f30ba2a

16 files changed

+232
-177
lines changed

src/RNGestureHandlerModule.macos.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import HammerPinchGestureHandler from './web_hammer/PinchGestureHandler';
2323
import HammerRotationGestureHandler from './web_hammer/RotationGestureHandler';
2424
import HammerFlingGestureHandler from './web_hammer/FlingGestureHandler';
2525
import { Config } from './web/interfaces';
26+
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
2627

2728
export const Gestures = {
2829
NativeViewGestureHandler,
@@ -65,7 +66,10 @@ export default {
6566
}
6667

6768
const GestureClass = Gestures[handlerName];
68-
NodeManager.createGestureHandler(handlerTag, new GestureClass());
69+
NodeManager.createGestureHandler(
70+
handlerTag,
71+
new GestureClass(new GestureHandlerWebDelegate())
72+
);
6973
InteractionManager.getInstance().configureInteractions(
7074
NodeManager.getHandler(handlerTag),
7175
config as unknown as Config

src/RNGestureHandlerModule.web.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import HammerPinchGestureHandler from './web_hammer/PinchGestureHandler';
2626
import HammerRotationGestureHandler from './web_hammer/RotationGestureHandler';
2727
import HammerFlingGestureHandler from './web_hammer/FlingGestureHandler';
2828
import { Config } from './web/interfaces';
29+
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
2930

3031
export const Gestures = {
3132
NativeViewGestureHandler,
@@ -69,7 +70,10 @@ export default {
6970
}
7071

7172
const GestureClass = Gestures[handlerName];
72-
NodeManager.createGestureHandler(handlerTag, new GestureClass());
73+
NodeManager.createGestureHandler(
74+
handlerTag,
75+
new GestureClass(new GestureHandlerWebDelegate())
76+
);
7377
InteractionManager.getInstance().configureInteractions(
7478
NodeManager.getHandler(handlerTag),
7579
config as unknown as Config

src/RNGestureHandlerModule.windows.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import HammerPinchGestureHandler from './web_hammer/PinchGestureHandler';
2525
import HammerRotationGestureHandler from './web_hammer/RotationGestureHandler';
2626
import HammerFlingGestureHandler from './web_hammer/FlingGestureHandler';
2727
import { Config } from './web/interfaces';
28+
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
2829

2930
export const Gestures = {
3031
NativeViewGestureHandler,
@@ -67,7 +68,10 @@ export default {
6768
}
6869

6970
const GestureClass = Gestures[handlerName];
70-
NodeManager.createGestureHandler(handlerTag, new GestureClass());
71+
NodeManager.createGestureHandler(
72+
handlerTag,
73+
new GestureClass(new GestureHandlerWebDelegate())
74+
);
7175
InteractionManager.getInstance().configureInteractions(
7276
NodeManager.getHandler(handlerTag),
7377
config as unknown as Config

src/web/handlers/FlingGestureHandler.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ export default class FlingGestureHandler extends GestureHandler {
3939
}
4040
}
4141

42-
protected transformNativeEvent() {
43-
const rect: DOMRect = this.view.getBoundingClientRect();
44-
45-
return {
46-
x: this.tracker.getLastAvgX() - rect.left,
47-
y: this.tracker.getLastAvgY() - rect.top,
48-
absoluteX: this.tracker.getLastAvgX(),
49-
absoluteY: this.tracker.getLastAvgY(),
50-
};
51-
}
52-
5342
private startFling(): void {
5443
this.startX = this.tracker.getLastX(this.keyPointer);
5544
this.startY = this.tracker.getLastY(this.keyPointer);

0 commit comments

Comments
 (0)