Skip to content

Commit 171cdb9

Browse files
committed
Access natively defined "nativeFabricUIManager" instead of importing it
Some places in the Fabric renderers access `nativeFabricUIManager` (a natively defined global) instead of importing UIManager. While this is coupling across repos that depends on the timing of events, it is necessary until we have a way to defer top-level imports to run after `nativeFabricUIManager` is defined. So for consistency we use `nativeFabricUIManager` everywhere (see the comment in facebook#15604 (review) for more context).
1 parent 10eab79 commit 171cdb9

File tree

6 files changed

+98
-114
lines changed

6 files changed

+98
-114
lines changed

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {dispatchEvent} from './ReactFabricEventEmitter';
2626

2727
// Modules provided by RN:
2828
import {
29-
FabricUIManager,
3029
ReactNativeViewConfigRegistry,
3130
TextInputState,
3231
deepFreezeAndThrowOnMutationInDev,
@@ -46,7 +45,7 @@ const {
4645
measure: fabricMeasure,
4746
measureInWindow: fabricMeasureInWindow,
4847
measureLayout: fabricMeasureLayout,
49-
} = FabricUIManager;
48+
} = nativeFabricUIManager;
5049

5150
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
5251

packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/FabricUIManager.js renamed to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ const RCTFabricUIManager = {
172172
}),
173173
};
174174

175-
module.exports = RCTFabricUIManager;
175+
global.nativeFabricUIManager = RCTFabricUIManager;

packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ module.exports = {
1717
get Platform() {
1818
return require('./Platform');
1919
},
20-
get FabricUIManager() {
21-
return require('./FabricUIManager');
22-
},
2320
get RCTEventEmitter() {
2421
return require('./RCTEventEmitter');
2522
},

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 60 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ let ReactFeatureFlags;
1616
let createReactClass;
1717
let createReactNativeComponentClass;
1818
let UIManager;
19-
let FabricUIManager;
2019
let StrictMode;
2120
let NativeMethodsMixin;
2221

@@ -31,13 +30,13 @@ describe('ReactFabric', () => {
3130
beforeEach(() => {
3231
jest.resetModules();
3332

33+
require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
34+
3435
React = require('react');
3536
StrictMode = React.StrictMode;
3637
ReactFeatureFlags = require('shared/ReactFeatureFlags');
3738
ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true;
3839
ReactFabric = require('react-native-renderer/fabric');
39-
FabricUIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
40-
.FabricUIManager;
4140
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
4241
.UIManager;
4342
createReactClass = require('create-react-class/factory')(
@@ -50,11 +49,6 @@ describe('ReactFabric', () => {
5049
NativeMethodsMixin =
5150
ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
5251
.NativeMethodsMixin;
53-
54-
global.nativeFabricUIManager = {
55-
measure: FabricUIManager.measure,
56-
measureInWindow: FabricUIManager.measureInWindow,
57-
};
5852
});
5953

6054
it('should be able to create and render a native component', () => {
@@ -64,9 +58,9 @@ describe('ReactFabric', () => {
6458
}));
6559

6660
ReactFabric.render(<View foo="test" />, 1);
67-
expect(FabricUIManager.createNode).toBeCalled();
68-
expect(FabricUIManager.appendChild).not.toBeCalled();
69-
expect(FabricUIManager.completeRoot).toBeCalled();
61+
expect(nativeFabricUIManager.createNode).toBeCalled();
62+
expect(nativeFabricUIManager.appendChild).not.toBeCalled();
63+
expect(nativeFabricUIManager.completeRoot).toBeCalled();
7064
});
7165

7266
it('should be able to create and update a native component', () => {
@@ -77,20 +71,20 @@ describe('ReactFabric', () => {
7771

7872
const firstNode = {};
7973

80-
FabricUIManager.createNode.mockReturnValue(firstNode);
74+
nativeFabricUIManager.createNode.mockReturnValue(firstNode);
8175

8276
ReactFabric.render(<View foo="foo" />, 11);
8377

84-
expect(FabricUIManager.createNode).toHaveBeenCalledTimes(1);
78+
expect(nativeFabricUIManager.createNode).toHaveBeenCalledTimes(1);
8579

8680
ReactFabric.render(<View foo="bar" />, 11);
8781

88-
expect(FabricUIManager.createNode).toHaveBeenCalledTimes(1);
89-
expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
90-
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][0]).toBe(
82+
expect(nativeFabricUIManager.createNode).toHaveBeenCalledTimes(1);
83+
expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
84+
expect(nativeFabricUIManager.cloneNodeWithNewProps.mock.calls[0][0]).toBe(
9185
firstNode,
9286
);
93-
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
87+
expect(nativeFabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
9488
foo: 'bar',
9589
});
9690
});
@@ -102,39 +96,39 @@ describe('ReactFabric', () => {
10296
}));
10397

10498
ReactFabric.render(<Text foo="a">1</Text>, 11);
105-
expect(FabricUIManager.cloneNode).not.toBeCalled();
106-
expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
107-
expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
108-
expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
99+
expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
100+
expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
101+
expect(nativeFabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
102+
expect(nativeFabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
109103

110104
// If no properties have changed, we shouldn't call cloneNode.
111105
ReactFabric.render(<Text foo="a">1</Text>, 11);
112-
expect(FabricUIManager.cloneNode).not.toBeCalled();
113-
expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
114-
expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
115-
expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
106+
expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
107+
expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
108+
expect(nativeFabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
109+
expect(nativeFabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
116110

117111
// Only call cloneNode for the changed property (and not for text).
118112
ReactFabric.render(<Text foo="b">1</Text>, 11);
119-
expect(FabricUIManager.cloneNode).not.toBeCalled();
120-
expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
121-
expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
122-
expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
113+
expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
114+
expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
115+
expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
116+
expect(nativeFabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
123117

124118
// Only call cloneNode for the changed text (and no other properties).
125119
ReactFabric.render(<Text foo="b">2</Text>, 11);
126-
expect(FabricUIManager.cloneNode).not.toBeCalled();
127-
expect(FabricUIManager.cloneNodeWithNewChildren).toHaveBeenCalledTimes(1);
128-
expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
129-
expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
120+
expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
121+
expect(nativeFabricUIManager.cloneNodeWithNewChildren).toHaveBeenCalledTimes(1);
122+
expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
123+
expect(nativeFabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
130124

131125
// Call cloneNode for both changed text and properties.
132126
ReactFabric.render(<Text foo="c">3</Text>, 11);
133-
expect(FabricUIManager.cloneNode).not.toBeCalled();
134-
expect(FabricUIManager.cloneNodeWithNewChildren).toHaveBeenCalledTimes(1);
135-
expect(FabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
127+
expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
128+
expect(nativeFabricUIManager.cloneNodeWithNewChildren).toHaveBeenCalledTimes(1);
129+
expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(1);
136130
expect(
137-
FabricUIManager.cloneNodeWithNewChildrenAndProps,
131+
nativeFabricUIManager.cloneNodeWithNewChildrenAndProps,
138132
).toHaveBeenCalledTimes(1);
139133
});
140134

@@ -150,21 +144,21 @@ describe('ReactFabric', () => {
150144
</Text>,
151145
11,
152146
);
153-
expect(FabricUIManager.cloneNode).not.toBeCalled();
154-
expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
155-
expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
156-
expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
147+
expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
148+
expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
149+
expect(nativeFabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
150+
expect(nativeFabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
157151

158152
ReactFabric.render(
159153
<Text foo="a" bar="b">
160154
1
161155
</Text>,
162156
11,
163157
);
164-
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
158+
expect(nativeFabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
165159
bar: 'b',
166160
});
167-
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
161+
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
168162

169163
ReactFabric.render(
170164
<Text foo="b" bar="b">
@@ -173,11 +167,11 @@ describe('ReactFabric', () => {
173167
11,
174168
);
175169
expect(
176-
FabricUIManager.cloneNodeWithNewChildrenAndProps.mock.calls[0][1],
170+
nativeFabricUIManager.cloneNodeWithNewChildrenAndProps.mock.calls[0][1],
177171
).toEqual({
178172
foo: 'b',
179173
});
180-
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
174+
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
181175
});
182176

183177
it('should not call UIManager.updateView from ref.setNativeProps', () => {
@@ -329,7 +323,7 @@ describe('ReactFabric', () => {
329323
});
330324

331325
[View, Subclass, CreateClass].forEach(Component => {
332-
FabricUIManager.measure.mockClear();
326+
nativeFabricUIManager.measure.mockClear();
333327

334328
let viewRef;
335329
ReactFabric.render(
@@ -341,10 +335,10 @@ describe('ReactFabric', () => {
341335
11,
342336
);
343337

344-
expect(FabricUIManager.measure).not.toBeCalled();
338+
expect(nativeFabricUIManager.measure).not.toBeCalled();
345339
const successCallback = jest.fn();
346340
viewRef.measure(successCallback);
347-
expect(FabricUIManager.measure).toHaveBeenCalledTimes(1);
341+
expect(nativeFabricUIManager.measure).toHaveBeenCalledTimes(1);
348342
expect(successCallback).toHaveBeenCalledTimes(1);
349343
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100, 0, 0);
350344
});
@@ -370,7 +364,7 @@ describe('ReactFabric', () => {
370364
});
371365

372366
[View, Subclass, CreateClass].forEach(Component => {
373-
FabricUIManager.measureInWindow.mockClear();
367+
nativeFabricUIManager.measureInWindow.mockClear();
374368

375369
let viewRef;
376370
ReactFabric.render(
@@ -382,10 +376,10 @@ describe('ReactFabric', () => {
382376
11,
383377
);
384378

385-
expect(FabricUIManager.measureInWindow).not.toBeCalled();
379+
expect(nativeFabricUIManager.measureInWindow).not.toBeCalled();
386380
const successCallback = jest.fn();
387381
viewRef.measureInWindow(successCallback);
388-
expect(FabricUIManager.measureInWindow).toHaveBeenCalledTimes(1);
382+
expect(nativeFabricUIManager.measureInWindow).toHaveBeenCalledTimes(1);
389383
expect(successCallback).toHaveBeenCalledTimes(1);
390384
expect(successCallback).toHaveBeenCalledWith(10, 10, 100, 100);
391385
});
@@ -398,7 +392,7 @@ describe('ReactFabric', () => {
398392
}));
399393

400394
[View].forEach(Component => {
401-
FabricUIManager.measureLayout.mockClear();
395+
nativeFabricUIManager.measureLayout.mockClear();
402396

403397
let viewRef;
404398
let otherRef;
@@ -419,11 +413,11 @@ describe('ReactFabric', () => {
419413
11,
420414
);
421415

422-
expect(FabricUIManager.measureLayout).not.toBeCalled();
416+
expect(nativeFabricUIManager.measureLayout).not.toBeCalled();
423417
const successCallback = jest.fn();
424418
const failureCallback = jest.fn();
425419
viewRef.measureLayout(otherRef, successCallback, failureCallback);
426-
expect(FabricUIManager.measureLayout).toHaveBeenCalledTimes(1);
420+
expect(nativeFabricUIManager.measureLayout).toHaveBeenCalledTimes(1);
427421
expect(successCallback).toHaveBeenCalledTimes(1);
428422
expect(successCallback).toHaveBeenCalledWith(1, 1, 100, 100);
429423
});
@@ -449,7 +443,7 @@ describe('ReactFabric', () => {
449443
});
450444

451445
[Subclass, CreateClass].forEach(Component => {
452-
FabricUIManager.measureLayout.mockReset();
446+
nativeFabricUIManager.measureLayout.mockReset();
453447

454448
let viewRef;
455449
let otherRef;
@@ -486,7 +480,7 @@ describe('ReactFabric', () => {
486480
},
487481
);
488482

489-
expect(FabricUIManager.measureLayout).not.toBeCalled();
483+
expect(nativeFabricUIManager.measureLayout).not.toBeCalled();
490484
expect(UIManager.measureLayout).not.toBeCalled();
491485
});
492486
});
@@ -532,10 +526,10 @@ describe('ReactFabric', () => {
532526
const after = 'mxhpgwfralkeoivcstzy';
533527

534528
ReactFabric.render(<Component chars={before} />, 11);
535-
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
529+
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
536530

537531
ReactFabric.render(<Component chars={after} />, 11);
538-
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
532+
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
539533
});
540534

541535
it('recreates host parents even if only children changed', () => {
@@ -567,14 +561,14 @@ describe('ReactFabric', () => {
567561
</View>,
568562
11,
569563
);
570-
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
564+
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
571565

572566
// Call setState() so that we skip over the top-level host node.
573567
// It should still get recreated despite a bailout.
574568
ref.current.setState({
575569
chars: after,
576570
});
577-
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
571+
expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
578572
});
579573

580574
it('calls setState with no arguments', () => {
@@ -599,12 +593,12 @@ describe('ReactFabric', () => {
599593
}));
600594

601595
const snapshots = [];
602-
FabricUIManager.completeRoot.mockImplementation(function(
596+
nativeFabricUIManager.completeRoot.mockImplementation(function(
603597
rootTag,
604598
newChildSet,
605599
) {
606600
snapshots.push(
607-
FabricUIManager.__dumpChildSetForJestTestsOnly(newChildSet),
601+
nativeFabricUIManager.__dumpChildSetForJestTestsOnly(newChildSet),
608602
);
609603
});
610604

@@ -706,11 +700,11 @@ describe('ReactFabric', () => {
706700

707701
ReactFabric.render(<View onTouchStart={touchStart} />, 11);
708702

709-
expect(FabricUIManager.createNode.mock.calls.length).toBe(1);
710-
expect(FabricUIManager.registerEventHandler.mock.calls.length).toBe(1);
703+
expect(nativeFabricUIManager.createNode.mock.calls.length).toBe(1);
704+
expect(nativeFabricUIManager.registerEventHandler.mock.calls.length).toBe(1);
711705

712-
let [, , , , instanceHandle] = FabricUIManager.createNode.mock.calls[0];
713-
let [dispatchEvent] = FabricUIManager.registerEventHandler.mock.calls[0];
706+
let [, , , , instanceHandle] = nativeFabricUIManager.createNode.mock.calls[0];
707+
let [dispatchEvent] = nativeFabricUIManager.registerEventHandler.mock.calls[0];
714708

715709
let touchEvent = {
716710
touches: [],

packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let createReactNativeComponentClass;
1919
describe('ReactFabric', () => {
2020
beforeEach(() => {
2121
jest.resetModules();
22+
require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
2223
ReactNative = require('react-native-renderer');
2324
jest.resetModules();
2425
UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')

0 commit comments

Comments
 (0)