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.


Reviewed By: sammy-SC

Differential Revision: D54903376
  • Loading branch information
rubennorte authored and facebook-github-bot committed Mar 20, 2024
1 parent ce4d8f2 commit 3dd6c6c
Show file tree
Hide file tree
Showing 16 changed files with 1,249 additions and 1,061 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import type {RootTag} from '../Types/RootTagTypes';
import type {UIManagerJSInterface} from '../Types/UIManagerJSInterface';

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

let result = FabricUIManager.compareDocumentPosition(
let result = NativeDOM.compareDocumentPosition(
ancestorShadowNode,
shadowNode,
);
Expand Down
53 changes: 0 additions & 53 deletions packages/react-native/Libraries/ReactNative/FabricUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ 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 +79,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 +104,7 @@ 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 3dd6c6c

Please sign in to comment.