Skip to content

Commit

Permalink
[React Native] Inline calls to FabricUIManager in shared code (#15490)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
elicwhite authored Apr 29, 2019
1 parent 2cca187 commit 12e5a13
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ module.exports = {
// https://github.com/jest-community/eslint-plugin-jest
'jest/no-focused-tests': ERROR,
}
},
{
files: ['packages/react-native-renderer/**/*.js'],
globals: {
nativeFabricUIManager: true,
}
}
],

Expand Down
11 changes: 8 additions & 3 deletions packages/react-native-renderer/src/NativeMethodsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
import invariant from 'shared/invariant';
// Modules provided by RN:
import TextInputState from 'TextInputState';
import * as FabricUIManager from 'FabricUIManager';
import UIManager from 'UIManager';

import {create} from './ReactNativeAttributePayload';
Expand Down Expand Up @@ -86,7 +85,10 @@ export default function(
}

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

if (maybeInstance.canonical) {
FabricUIManager.measureInWindow(
// We can't call FabricUIManager here because it won't be loaded in paper
// at initialization time. See https://github.com/facebook/react/pull/15490
// for more info.
nativeFabricUIManager.measureInWindow(
maybeInstance.node,
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
);
Expand Down
11 changes: 8 additions & 3 deletions packages/react-native-renderer/src/ReactNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
import React from 'react';
// Modules provided by RN:
import TextInputState from 'TextInputState';
import * as FabricUIManager from 'FabricUIManager';
import UIManager from 'UIManager';

import {create} from './ReactNativeAttributePayload';
Expand Down Expand Up @@ -101,7 +100,10 @@ export default function(
}

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

if (maybeInstance.canonical) {
FabricUIManager.measureInWindow(
// We can't call FabricUIManager here because it won't be loaded in paper
// at initialization time. See https://github.com/facebook/react/pull/15490
// for more info.
nativeFabricUIManager.measureInWindow(
maybeInstance.node,
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ describe('ReactFabric', () => {
NativeMethodsMixin =
ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.NativeMethodsMixin;

global.nativeFabricUIManager = {
measure: FabricUIManager.measure,
measureInWindow: FabricUIManager.measureInWindow,
};
});

it('should be able to create and render a native component', () => {
Expand Down
7 changes: 7 additions & 0 deletions scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ declare module 'FabricUIManager' {
): void;
}

// This is needed for a short term solution.
// See https://github.com/facebook/react/pull/15490 for more info
declare var nativeFabricUIManager: {
measure(node: Node, callback: MeasureOnSuccessCallback): void,
measureInWindow(node: Node, callback: MeasureInWindowOnSuccessCallback): void,
};

declare module 'View' {
declare module.exports: typeof React$Component;
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/rollup/validate/eslintrc.rn.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = {
__REACT_DEVTOOLS_GLOBAL_HOOK__: true,
// FB
__DEV__: true,
// Fabric. See https://github.com/facebook/react/pull/15490
// for more information
nativeFabricUIManager: true,
},
parserOptions: {
ecmaVersion: 5,
Expand Down

0 comments on commit 12e5a13

Please sign in to comment.