Skip to content

Commit aee7d96

Browse files
rubennortefacebook-github-bot
authored andcommitted
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
1 parent ea57c92 commit aee7d96

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

Libraries/LayoutAnimation/LayoutAnimation.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
'use strict';
1212

13-
import type {Spec as FabricUIManagerSpec} from '../ReactNative/FabricUIManager';
1413
import type {
1514
LayoutAnimationConfig as LayoutAnimationConfig_,
1615
LayoutAnimationProperty,
1716
LayoutAnimationType,
1817
} from '../Renderer/shims/ReactNativeTypes';
1918

19+
import FabricUIManager from '../ReactNative/FabricUIManager';
2020
import ReactNativeFeatureFlags from '../ReactNative/ReactNativeFeatureFlags';
2121
import Platform from '../Utilities/Platform';
2222

@@ -77,9 +77,8 @@ function configureNext(
7777

7878
// In Fabric, LayoutAnimations are unconditionally enabled for Android, and
7979
// conditionally enabled on iOS (pending fully shipping; this is a temporary state).
80-
const FabricUIManager: FabricUIManagerSpec = global?.nativeFabricUIManager;
8180
if (FabricUIManager?.configureNextLayoutAnimation) {
82-
global?.nativeFabricUIManager?.configureNextLayoutAnimation(
81+
FabricUIManager.configureNextLayoutAnimation(
8382
config,
8483
onAnimationComplete,
8584
onAnimationDidFail ??

Libraries/ReactNative/UIManager.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
*/
1010

1111
import type {RootTag} from '../Types/RootTagTypes';
12-
import type {Spec as FabricUIManagerSpec} from './FabricUIManager';
1312
import type {Spec} from './NativeUIManager';
1413

14+
import MaybeFabricUIManager from './FabricUIManager';
15+
import nullthrows from 'nullthrows';
16+
1517
export interface UIManagerJSInterface extends Spec {
1618
+getViewManagerConfig: (viewManagerName: string) => Object;
1719
+hasViewManagerConfig: (viewManagerName: string) => boolean;
@@ -57,8 +59,7 @@ const UIManager = {
5759
) => void,
5860
): void {
5961
if (isFabricReactTag(reactTag)) {
60-
const FabricUIManager: FabricUIManagerSpec =
61-
global?.nativeFabricUIManager;
62+
const FabricUIManager = nullthrows(MaybeFabricUIManager);
6263
const shadowNode =
6364
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
6465
if (shadowNode) {
@@ -84,8 +85,7 @@ const UIManager = {
8485
) => void,
8586
): void {
8687
if (isFabricReactTag(reactTag)) {
87-
const FabricUIManager: FabricUIManagerSpec =
88-
global?.nativeFabricUIManager;
88+
const FabricUIManager = nullthrows(MaybeFabricUIManager);
8989
const shadowNode =
9090
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
9191
if (shadowNode) {
@@ -113,8 +113,7 @@ const UIManager = {
113113
) => void,
114114
): void {
115115
if (isFabricReactTag(reactTag)) {
116-
const FabricUIManager: FabricUIManagerSpec =
117-
global?.nativeFabricUIManager;
116+
const FabricUIManager = nullthrows(MaybeFabricUIManager);
118117
const shadowNode =
119118
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
120119
const ancestorShadowNode =
@@ -155,8 +154,7 @@ const UIManager = {
155154
console.warn(
156155
'RCTUIManager.measureLayoutRelativeToParent method is deprecated and it will not be implemented in newer versions of RN (Fabric) - T47686450',
157156
);
158-
const FabricUIManager: FabricUIManagerSpec =
159-
global?.nativeFabricUIManager;
157+
const FabricUIManager = nullthrows(MaybeFabricUIManager);
160158
const shadowNode =
161159
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
162160
if (shadowNode) {

0 commit comments

Comments
 (0)