Skip to content

Commit

Permalink
Move DOM APIs to native module (facebook#43512)
Browse files Browse the repository at this point in the history
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.

Pull Request resolved: facebook#43512

Reviewed By: sammy-SC

Differential Revision: D54903376

fbshipit-source-id: 69daa84c886d1c65dbb0b223dbb7c9077502c6ad
  • Loading branch information
rubennorte authored and facebook-github-bot committed Mar 20, 2024
1 parent 21b008e commit 0267ca0
Show file tree
Hide file tree
Showing 15 changed files with 1,261 additions and 1,053 deletions.
51 changes: 0 additions & 51 deletions packages/react-native/Libraries/ReactNative/FabricUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,7 @@ export interface Spec {
locationY: number,
callback: (instanceHandle: ?InternalInstanceHandle) => void,
) => void;

/**
* Support methods for the DOM-compatible APIs.
*/
+getParentNode: (node: Node) => ?InternalInstanceHandle;
+getChildNodes: (node: Node) => $ReadOnlyArray<InternalInstanceHandle>;
+isConnected: (node: Node) => boolean;
+compareDocumentPosition: (node: Node, otherNode: Node) => number;
+getTextContent: (node: Node) => string;
+getBoundingClientRect: (
node: Node,
includeTransform: boolean,
Expand All @@ -88,36 +80,6 @@ export interface Spec {
/* width: */ number,
/* height: */ number,
];
+getOffset: (
node: Node,
) => ?[
/* offsetParent: */ InternalInstanceHandle,
/* offsetTop: */ number,
/* offsetLeft: */ number,
];
+getScrollPosition: (
node: Node,
) => ?[/* scrollLeft: */ number, /* scrollTop: */ number];
+getScrollSize: (
node: Node,
) => ?[/* scrollWidth: */ number, /* scrollHeight: */ number];
+getInnerSize: (node: Node) => ?[/* width: */ number, /* height: */ number];
+getBorderSize: (
node: Node,
) => ?[
/* topWidth: */ number,
/* rightWidth: */ number,
/* bottomWidth: */ number,
/* leftWidth: */ number,
];
+getTagName: (node: Node) => string;

/**
* Support methods for the Pointer Capture APIs.
*/
+hasPointerCapture: (node: Node, pointerId: number) => boolean;
+setPointerCapture: (node: Node, pointerId: number) => void;
+releasePointerCapture: (node: Node, pointerId: number) => void;
}

let nativeFabricUIManagerProxy: ?Spec;
Expand All @@ -143,21 +105,8 @@ const CACHED_PROPERTIES = [
'findShadowNodeByTag_DEPRECATED',
'setNativeProps',
'dispatchCommand',
'getParentNode',
'getChildNodes',
'isConnected',
'compareDocumentPosition',
'getTextContent',
'getBoundingClientRect',
'getOffset',
'getScrollPosition',
'getScrollSize',
'getInnerSize',
'getBorderSize',
'getTagName',
'hasPointerCapture',
'setPointerCapture',
'releasePointerCapture',
];

// This is exposed as a getter because apps using the legacy renderer AND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jest.mock('../../FabricUIManager', () =>
require('../../__mocks__/FabricUIManager'),
);

jest.mock('../../../../src/private/webapis/dom/nodes/specs/NativeDOM', () =>
require('../../../../src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock'),
);

/**
* Given a mocked function, get a correctly typed mock function that preserves
* the original function's type.
Expand Down
Loading

0 comments on commit 0267ca0

Please sign in to comment.