From f49083db6956a79fc9332e4359d1f18538fb1376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 15 May 2025 08:46:32 -0700 Subject: [PATCH] Replace usage of FabricUIManager methods with NativeDOM methods where available (#51341) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51341 Changelog: [internal] `measure`, `measureInWindow` and `measureLayout` have been defined in the `NativeDOM` C++ TurboModule for a while, but we didn't migrate the callsites in the DOM APIs to use them. This does that migration so we can remove a few `$FlowFixMe`s and use a cleaner API. Reviewed By: javache Differential Revision: D74800814 fbshipit-source-id: 117e4a8798036f2266e25cfc0931e91c148eaf52 --- .../webapis/dom/nodes/ReactNativeElement.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js b/packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js index d4f669e8fe2..7cca0cc8009 100644 --- a/packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js +++ b/packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js @@ -153,18 +153,14 @@ class ReactNativeElement extends ReadOnlyElement implements NativeMethods { measure(callback: MeasureOnSuccessCallback) { const node = getNativeElementReference(this); if (node != null) { - // $FlowExpectedError[incompatible-type] This is an element instance so the native node reference is always a shadow node. - const shadowNode: ShadowNode = node; - nullthrows(getFabricUIManager()).measure(shadowNode, callback); + NativeDOM.measure(node, callback); } } measureInWindow(callback: MeasureInWindowOnSuccessCallback) { const node = getNativeElementReference(this); if (node != null) { - // $FlowExpectedError[incompatible-type] This is an element instance so the native node reference is always a shadow node. - const shadowNode: ShadowNode = node; - nullthrows(getFabricUIManager()).measureInWindow(shadowNode, callback); + NativeDOM.measureInWindow(node, callback); } } @@ -187,14 +183,9 @@ class ReactNativeElement extends ReadOnlyElement implements NativeMethods { const fromStateNode = getNativeElementReference(relativeToNativeNode); if (toStateNode != null && fromStateNode != null) { - // $FlowExpectedError[incompatible-type] This is an element instance so the native node reference is always a shadow node. - const toStateShadowNode: ShadowNode = toStateNode; - // $FlowExpectedError[incompatible-type] This is an element instance so the native node reference is always a shadow node. - const fromStateShadowNode: ShadowNode = fromStateNode; - - nullthrows(getFabricUIManager()).measureLayout( - toStateShadowNode, - fromStateShadowNode, + NativeDOM.measureLayout( + toStateNode, + fromStateNode, onFail != null ? onFail : noop, onSuccess != null ? onSuccess : noop, );