Skip to content

Commit 12e5a13

Browse files
authored
[React Native] Inline calls to FabricUIManager in shared code (#15490)
* [React Native] Inline calls to FabricUIManager in shared code * Call global.nativeFabricUIManager directly as short term fix * Add flow types * Add nativeFabricUIManager global to eslint config * Adding eslint global to bundle validation script
1 parent 2cca187 commit 12e5a13

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ module.exports = {
125125
// https://github.com/jest-community/eslint-plugin-jest
126126
'jest/no-focused-tests': ERROR,
127127
}
128+
},
129+
{
130+
files: ['packages/react-native-renderer/**/*.js'],
131+
globals: {
132+
nativeFabricUIManager: true,
133+
}
128134
}
129135
],
130136

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type {
1818
import invariant from 'shared/invariant';
1919
// Modules provided by RN:
2020
import TextInputState from 'TextInputState';
21-
import * as FabricUIManager from 'FabricUIManager';
2221
import UIManager from 'UIManager';
2322

2423
import {create} from './ReactNativeAttributePayload';
@@ -86,7 +85,10 @@ export default function(
8685
}
8786

8887
if (maybeInstance.canonical) {
89-
FabricUIManager.measure(
88+
// We can't call FabricUIManager here because it won't be loaded in paper
89+
// at initialization time. See https://github.com/facebook/react/pull/15490
90+
// for more info.
91+
nativeFabricUIManager.measure(
9092
maybeInstance.node,
9193
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
9294
);
@@ -131,7 +133,10 @@ export default function(
131133
}
132134

133135
if (maybeInstance.canonical) {
134-
FabricUIManager.measureInWindow(
136+
// We can't call FabricUIManager here because it won't be loaded in paper
137+
// at initialization time. See https://github.com/facebook/react/pull/15490
138+
// for more info.
139+
nativeFabricUIManager.measureInWindow(
135140
maybeInstance.node,
136141
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
137142
);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
import React from 'react';
2020
// Modules provided by RN:
2121
import TextInputState from 'TextInputState';
22-
import * as FabricUIManager from 'FabricUIManager';
2322
import UIManager from 'UIManager';
2423

2524
import {create} from './ReactNativeAttributePayload';
@@ -101,7 +100,10 @@ export default function(
101100
}
102101

103102
if (maybeInstance.canonical) {
104-
FabricUIManager.measure(
103+
// We can't call FabricUIManager here because it won't be loaded in paper
104+
// at initialization time. See https://github.com/facebook/react/pull/15490
105+
// for more info.
106+
nativeFabricUIManager.measure(
105107
maybeInstance.node,
106108
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
107109
);
@@ -144,7 +146,10 @@ export default function(
144146
}
145147

146148
if (maybeInstance.canonical) {
147-
FabricUIManager.measureInWindow(
149+
// We can't call FabricUIManager here because it won't be loaded in paper
150+
// at initialization time. See https://github.com/facebook/react/pull/15490
151+
// for more info.
152+
nativeFabricUIManager.measureInWindow(
148153
maybeInstance.node,
149154
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
150155
);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ describe('ReactFabric', () => {
4848
NativeMethodsMixin =
4949
ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
5050
.NativeMethodsMixin;
51+
52+
global.nativeFabricUIManager = {
53+
measure: FabricUIManager.measure,
54+
measureInWindow: FabricUIManager.measureInWindow,
55+
};
5156
});
5257

5358
it('should be able to create and render a native component', () => {

scripts/flow/react-native-host-hooks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ declare module 'FabricUIManager' {
144144
): void;
145145
}
146146

147+
// This is needed for a short term solution.
148+
// See https://github.com/facebook/react/pull/15490 for more info
149+
declare var nativeFabricUIManager: {
150+
measure(node: Node, callback: MeasureOnSuccessCallback): void,
151+
measureInWindow(node: Node, callback: MeasureInWindowOnSuccessCallback): void,
152+
};
153+
147154
declare module 'View' {
148155
declare module.exports: typeof React$Component;
149156
}

scripts/rollup/validate/eslintrc.rn.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module.exports = {
1818
__REACT_DEVTOOLS_GLOBAL_HOOK__: true,
1919
// FB
2020
__DEV__: true,
21+
// Fabric. See https://github.com/facebook/react/pull/15490
22+
// for more information
23+
nativeFabricUIManager: true,
2124
},
2225
parserOptions: {
2326
ecmaVersion: 5,

0 commit comments

Comments
 (0)