Skip to content

Commit ad80c66

Browse files
rubennortefacebook-github-bot
authored andcommitted
Move DOM APIs to native module (#43512)
Summary: Changelog: [internal] This moves all the new methods that were added to implement the DOM traversal and layout APIs (as per this RFC: react-native-community/discussions-and-proposals#607) to a separate C++ native module to avoid bloating the UIManager interface, initialize lazily, provide automatic caching of methods, simplify the API for implementors, etc. Reviewed By: sammy-SC Differential Revision: D54903376
1 parent ec6d027 commit ad80c66

File tree

16 files changed

+1249
-1061
lines changed

16 files changed

+1249
-1061
lines changed

packages/react-native/Libraries/ReactNative/BridgelessUIManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import type {RootTag} from '../Types/RootTagTypes';
1414
import type {UIManagerJSInterface} from '../Types/UIManagerJSInterface';
1515

16+
import NativeDOM from '../../src/private/webapis/dom/nodes/specs/NativeDOM';
1617
import {unstable_hasComponent} from '../NativeComponent/NativeComponentRegistryUnstable';
1718
import defineLazyObjectProperty from '../Utilities/defineLazyObjectProperty';
1819
import Platform from '../Utilities/Platform';
@@ -397,7 +398,7 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
397398
// Keep this in sync with ReadOnlyNode.js
398399
const DOCUMENT_POSITION_CONTAINED_BY = 16;
399400

400-
let result = FabricUIManager.compareDocumentPosition(
401+
let result = NativeDOM.compareDocumentPosition(
401402
ancestorShadowNode,
402403
shadowNode,
403404
);

packages/react-native/Libraries/ReactNative/FabricUIManager.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ export interface Spec {
7070
locationY: number,
7171
callback: (instanceHandle: ?InternalInstanceHandle) => void,
7272
) => void;
73-
74-
/**
75-
* Support methods for the DOM-compatible APIs.
76-
*/
77-
+getParentNode: (node: Node) => ?InternalInstanceHandle;
78-
+getChildNodes: (node: Node) => $ReadOnlyArray<InternalInstanceHandle>;
79-
+isConnected: (node: Node) => boolean;
80-
+compareDocumentPosition: (node: Node, otherNode: Node) => number;
81-
+getTextContent: (node: Node) => string;
8273
+getBoundingClientRect: (
8374
node: Node,
8475
includeTransform: boolean,
@@ -88,36 +79,6 @@ export interface Spec {
8879
/* width: */ number,
8980
/* height: */ number,
9081
];
91-
+getOffset: (
92-
node: Node,
93-
) => ?[
94-
/* offsetParent: */ InternalInstanceHandle,
95-
/* offsetTop: */ number,
96-
/* offsetLeft: */ number,
97-
];
98-
+getScrollPosition: (
99-
node: Node,
100-
) => ?[/* scrollLeft: */ number, /* scrollTop: */ number];
101-
+getScrollSize: (
102-
node: Node,
103-
) => ?[/* scrollWidth: */ number, /* scrollHeight: */ number];
104-
+getInnerSize: (node: Node) => ?[/* width: */ number, /* height: */ number];
105-
+getBorderSize: (
106-
node: Node,
107-
) => ?[
108-
/* topWidth: */ number,
109-
/* rightWidth: */ number,
110-
/* bottomWidth: */ number,
111-
/* leftWidth: */ number,
112-
];
113-
+getTagName: (node: Node) => string;
114-
115-
/**
116-
* Support methods for the Pointer Capture APIs.
117-
*/
118-
+hasPointerCapture: (node: Node, pointerId: number) => boolean;
119-
+setPointerCapture: (node: Node, pointerId: number) => void;
120-
+releasePointerCapture: (node: Node, pointerId: number) => void;
12182
}
12283

12384
let nativeFabricUIManagerProxy: ?Spec;
@@ -143,21 +104,7 @@ const CACHED_PROPERTIES = [
143104
'findShadowNodeByTag_DEPRECATED',
144105
'setNativeProps',
145106
'dispatchCommand',
146-
'getParentNode',
147-
'getChildNodes',
148-
'isConnected',
149-
'compareDocumentPosition',
150-
'getTextContent',
151107
'getBoundingClientRect',
152-
'getOffset',
153-
'getScrollPosition',
154-
'getScrollSize',
155-
'getInnerSize',
156-
'getBorderSize',
157-
'getTagName',
158-
'hasPointerCapture',
159-
'setPointerCapture',
160-
'releasePointerCapture',
161108
];
162109

163110
// This is exposed as a getter because apps using the legacy renderer AND

packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/__tests__/ReactFabricPublicInstance-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jest.mock('../../FabricUIManager', () =>
3232
require('../../__mocks__/FabricUIManager'),
3333
);
3434

35+
jest.mock('../../../../src/private/webapis/dom/nodes/specs/NativeDOM', () =>
36+
require('../../../../src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock'),
37+
);
38+
3539
/**
3640
* Given a mocked function, get a correctly typed mock function that preserves
3741
* the original function's type.

0 commit comments

Comments
 (0)