Skip to content

Commit 8b2470a

Browse files
authored
Revert "Change .web files to default and add .native (#2835)" (#2896)
## Description This reverts commit e3e0b79. #2835 was the first PR that was meant to introduce compatibility with `Next.js`. Unfortunately, it broke types outside of our repository. Our `tsconfig.json` has special flag, i.e. `moduleSuffixes`, which allows `tsc` to look for `.native` files first. Most of our users do not have this flag and they've run into `ts` problems, like this one: ``` 'TextInput' refers to a value, but is being used as a type here. Did you mean 'typeof TextInput'? ``` Given that removing `moduleSuffixes` from `tsconfig` results in a bunch of errors (and there are more of them that we may not be aware of), we decided that it will be better to revert this change for now. It is not necessary since we only need it to support `Next.js`. At first I thought that #2873 may help, but unfortunately it doesn't. Fixes #2889 ## Test plan 1. Check that web, Android and iOS work as they did before 2. Check that code from [this comment](#2835 (comment)) now does not throw any errors
1 parent a1e54bc commit 8b2470a

28 files changed

Lines changed: 382 additions & 389 deletions

src/RNGestureHandlerModule.native.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/RNGestureHandlerModule.ts

Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,5 @@
1-
import React from 'react';
1+
// Reexport the native module spec used by codegen. The relevant files are inluded on Android
2+
// to ensure the compatibility with the old arch, while iOS doesn't require those at all.
23

3-
import type { ActionType } from './ActionType';
4-
import { isNewWebImplementationEnabled } from './EnableNewWebImplementation';
5-
import { Gestures, HammerGestures } from './web/Gestures';
6-
import type { Config } from './web/interfaces';
7-
import InteractionManager from './web/tools/InteractionManager';
8-
import NodeManager from './web/tools/NodeManager';
9-
import * as HammerNodeManager from './web_hammer/NodeManager';
10-
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
11-
12-
export default {
13-
handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
14-
console.warn('handleSetJSResponder: ', tag, blockNativeResponder);
15-
},
16-
handleClearJSResponder() {
17-
console.warn('handleClearJSResponder: ');
18-
},
19-
createGestureHandler<T>(
20-
handlerName: keyof typeof Gestures,
21-
handlerTag: number,
22-
config: T
23-
) {
24-
if (isNewWebImplementationEnabled()) {
25-
if (!(handlerName in Gestures)) {
26-
throw new Error(
27-
`react-native-gesture-handler: ${handlerName} is not supported on web.`
28-
);
29-
}
30-
31-
const GestureClass = Gestures[handlerName];
32-
NodeManager.createGestureHandler(
33-
handlerTag,
34-
new GestureClass(new GestureHandlerWebDelegate())
35-
);
36-
InteractionManager.getInstance().configureInteractions(
37-
NodeManager.getHandler(handlerTag),
38-
config as unknown as Config
39-
);
40-
} else {
41-
if (!(handlerName in HammerGestures)) {
42-
throw new Error(
43-
`react-native-gesture-handler: ${handlerName} is not supported on web.`
44-
);
45-
}
46-
47-
// @ts-ignore If it doesn't exist, the error is thrown
48-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
49-
const GestureClass = HammerGestures[handlerName];
50-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
51-
HammerNodeManager.createGestureHandler(handlerTag, new GestureClass());
52-
}
53-
54-
this.updateGestureHandler(handlerTag, config as unknown as Config);
55-
},
56-
attachGestureHandler(
57-
handlerTag: number,
58-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59-
newView: any,
60-
_actionType: ActionType,
61-
propsRef: React.RefObject<unknown>
62-
) {
63-
if (
64-
!(newView instanceof HTMLElement || newView instanceof React.Component)
65-
) {
66-
return;
67-
}
68-
69-
if (isNewWebImplementationEnabled()) {
70-
//@ts-ignore Types should be HTMLElement or React.Component
71-
NodeManager.getHandler(handlerTag).init(newView, propsRef);
72-
} else {
73-
//@ts-ignore Types should be HTMLElement or React.Component
74-
HammerNodeManager.getHandler(handlerTag).setView(newView, propsRef);
75-
}
76-
},
77-
updateGestureHandler(handlerTag: number, newConfig: Config) {
78-
if (isNewWebImplementationEnabled()) {
79-
NodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);
80-
81-
InteractionManager.getInstance().configureInteractions(
82-
NodeManager.getHandler(handlerTag),
83-
newConfig
84-
);
85-
} else {
86-
HammerNodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);
87-
}
88-
},
89-
getGestureHandlerNode(handlerTag: number) {
90-
if (isNewWebImplementationEnabled()) {
91-
return NodeManager.getHandler(handlerTag);
92-
} else {
93-
return HammerNodeManager.getHandler(handlerTag);
94-
}
95-
},
96-
dropGestureHandler(handlerTag: number) {
97-
if (isNewWebImplementationEnabled()) {
98-
NodeManager.dropGestureHandler(handlerTag);
99-
} else {
100-
HammerNodeManager.dropGestureHandler(handlerTag);
101-
}
102-
},
103-
// eslint-disable-next-line @typescript-eslint/no-empty-function
104-
flushOperations() {},
105-
};
4+
import Module from './specs/NativeRNGestureHandlerModule';
5+
export default Module;

src/RNGestureHandlerModule.web.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import React from 'react';
2+
3+
import type { ActionType } from './ActionType';
4+
import { isNewWebImplementationEnabled } from './EnableNewWebImplementation';
5+
import { Gestures, HammerGestures } from './web/Gestures';
6+
import type { Config } from './web/interfaces';
7+
import InteractionManager from './web/tools/InteractionManager';
8+
import NodeManager from './web/tools/NodeManager';
9+
import * as HammerNodeManager from './web_hammer/NodeManager';
10+
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
11+
12+
export default {
13+
handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
14+
console.warn('handleSetJSResponder: ', tag, blockNativeResponder);
15+
},
16+
handleClearJSResponder() {
17+
console.warn('handleClearJSResponder: ');
18+
},
19+
createGestureHandler<T>(
20+
handlerName: keyof typeof Gestures,
21+
handlerTag: number,
22+
config: T
23+
) {
24+
if (isNewWebImplementationEnabled()) {
25+
if (!(handlerName in Gestures)) {
26+
throw new Error(
27+
`react-native-gesture-handler: ${handlerName} is not supported on web.`
28+
);
29+
}
30+
31+
const GestureClass = Gestures[handlerName];
32+
NodeManager.createGestureHandler(
33+
handlerTag,
34+
new GestureClass(new GestureHandlerWebDelegate())
35+
);
36+
InteractionManager.getInstance().configureInteractions(
37+
NodeManager.getHandler(handlerTag),
38+
config as unknown as Config
39+
);
40+
} else {
41+
if (!(handlerName in HammerGestures)) {
42+
throw new Error(
43+
`react-native-gesture-handler: ${handlerName} is not supported on web.`
44+
);
45+
}
46+
47+
// @ts-ignore If it doesn't exist, the error is thrown
48+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
49+
const GestureClass = HammerGestures[handlerName];
50+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
51+
HammerNodeManager.createGestureHandler(handlerTag, new GestureClass());
52+
}
53+
54+
this.updateGestureHandler(handlerTag, config as unknown as Config);
55+
},
56+
attachGestureHandler(
57+
handlerTag: number,
58+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59+
newView: any,
60+
_actionType: ActionType,
61+
propsRef: React.RefObject<unknown>
62+
) {
63+
if (
64+
!(newView instanceof HTMLElement || newView instanceof React.Component)
65+
) {
66+
return;
67+
}
68+
69+
if (isNewWebImplementationEnabled()) {
70+
//@ts-ignore Types should be HTMLElement or React.Component
71+
NodeManager.getHandler(handlerTag).init(newView, propsRef);
72+
} else {
73+
//@ts-ignore Types should be HTMLElement or React.Component
74+
HammerNodeManager.getHandler(handlerTag).setView(newView, propsRef);
75+
}
76+
},
77+
updateGestureHandler(handlerTag: number, newConfig: Config) {
78+
if (isNewWebImplementationEnabled()) {
79+
NodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);
80+
81+
InteractionManager.getInstance().configureInteractions(
82+
NodeManager.getHandler(handlerTag),
83+
newConfig
84+
);
85+
} else {
86+
HammerNodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);
87+
}
88+
},
89+
getGestureHandlerNode(handlerTag: number) {
90+
if (isNewWebImplementationEnabled()) {
91+
return NodeManager.getHandler(handlerTag);
92+
} else {
93+
return HammerNodeManager.getHandler(handlerTag);
94+
}
95+
},
96+
dropGestureHandler(handlerTag: number) {
97+
if (isNewWebImplementationEnabled()) {
98+
NodeManager.dropGestureHandler(handlerTag);
99+
} else {
100+
HammerNodeManager.dropGestureHandler(handlerTag);
101+
}
102+
},
103+
// eslint-disable-next-line @typescript-eslint/no-empty-function
104+
flushOperations() {},
105+
};

src/RNRenderer.native.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/RNRenderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const RNRenderer = {
2-
findHostInstance_DEPRECATED: (_ref: any) => null,
3-
};
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-nocheck
3+
export { default as RNRenderer } from 'react-native/Libraries/Renderer/shims/ReactNative';

src/RNRenderer.web.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const RNRenderer = {
2+
findHostInstance_DEPRECATED: (_ref: any) => null,
3+
};

src/components/GestureComponents.native.tsx

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)