From aee7d96fcd5bb84147a676984dea71fb7a195ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 14 Mar 2023 08:48:24 -0700 Subject: [PATCH] Remove direct references to the global and untyped nativeFabricUIManager Summary: We shouldn't be accessing `nativeFabricUIManager` directly because it's untyped and makes it harder to mock the values. This migrates all existing usages to the `FabricUIManager` module. In the long term, we should refactor this global binding as a TurboModule. Changelog: [internal] Reviewed By: yungsters Differential Revision: D44029301 fbshipit-source-id: d8300acb5dabe4ba27c7f0242230e203c0e8c674 --- Libraries/LayoutAnimation/LayoutAnimation.js | 5 ++--- Libraries/ReactNative/UIManager.js | 16 +++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Libraries/LayoutAnimation/LayoutAnimation.js b/Libraries/LayoutAnimation/LayoutAnimation.js index a8c20e3960c..3d5aac06be1 100644 --- a/Libraries/LayoutAnimation/LayoutAnimation.js +++ b/Libraries/LayoutAnimation/LayoutAnimation.js @@ -10,13 +10,13 @@ 'use strict'; -import type {Spec as FabricUIManagerSpec} from '../ReactNative/FabricUIManager'; import type { LayoutAnimationConfig as LayoutAnimationConfig_, LayoutAnimationProperty, LayoutAnimationType, } from '../Renderer/shims/ReactNativeTypes'; +import FabricUIManager from '../ReactNative/FabricUIManager'; import ReactNativeFeatureFlags from '../ReactNative/ReactNativeFeatureFlags'; import Platform from '../Utilities/Platform'; @@ -77,9 +77,8 @@ function configureNext( // In Fabric, LayoutAnimations are unconditionally enabled for Android, and // conditionally enabled on iOS (pending fully shipping; this is a temporary state). - const FabricUIManager: FabricUIManagerSpec = global?.nativeFabricUIManager; if (FabricUIManager?.configureNextLayoutAnimation) { - global?.nativeFabricUIManager?.configureNextLayoutAnimation( + FabricUIManager.configureNextLayoutAnimation( config, onAnimationComplete, onAnimationDidFail ?? diff --git a/Libraries/ReactNative/UIManager.js b/Libraries/ReactNative/UIManager.js index ac28590f23d..7555f0a4a2c 100644 --- a/Libraries/ReactNative/UIManager.js +++ b/Libraries/ReactNative/UIManager.js @@ -9,9 +9,11 @@ */ import type {RootTag} from '../Types/RootTagTypes'; -import type {Spec as FabricUIManagerSpec} from './FabricUIManager'; import type {Spec} from './NativeUIManager'; +import MaybeFabricUIManager from './FabricUIManager'; +import nullthrows from 'nullthrows'; + export interface UIManagerJSInterface extends Spec { +getViewManagerConfig: (viewManagerName: string) => Object; +hasViewManagerConfig: (viewManagerName: string) => boolean; @@ -57,8 +59,7 @@ const UIManager = { ) => void, ): void { if (isFabricReactTag(reactTag)) { - const FabricUIManager: FabricUIManagerSpec = - global?.nativeFabricUIManager; + const FabricUIManager = nullthrows(MaybeFabricUIManager); const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag); if (shadowNode) { @@ -84,8 +85,7 @@ const UIManager = { ) => void, ): void { if (isFabricReactTag(reactTag)) { - const FabricUIManager: FabricUIManagerSpec = - global?.nativeFabricUIManager; + const FabricUIManager = nullthrows(MaybeFabricUIManager); const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag); if (shadowNode) { @@ -113,8 +113,7 @@ const UIManager = { ) => void, ): void { if (isFabricReactTag(reactTag)) { - const FabricUIManager: FabricUIManagerSpec = - global?.nativeFabricUIManager; + const FabricUIManager = nullthrows(MaybeFabricUIManager); const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag); const ancestorShadowNode = @@ -155,8 +154,7 @@ const UIManager = { console.warn( 'RCTUIManager.measureLayoutRelativeToParent method is deprecated and it will not be implemented in newer versions of RN (Fabric) - T47686450', ); - const FabricUIManager: FabricUIManagerSpec = - global?.nativeFabricUIManager; + const FabricUIManager = nullthrows(MaybeFabricUIManager); const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag); if (shadowNode) {