From 822649b7a43c80afeaa7d654c6bdbab45874e9ea Mon Sep 17 00:00:00 2001 From: James Ide Date: Wed, 8 May 2019 18:58:18 -0700 Subject: [PATCH] [react-native] Use path-based imports instead of Haste for the RN renderer To move React Native to standard path-based imports instead of Haste, the RN renderer that is generated from the code in this repo needs to use path-based imports as well since the generated code is vendored by RN. This commit makes it so the interface between the generated renderers and RN does not rely on Haste and instead uses a private interface explicitly defined by RN. This inverts control of the abstraction so that RN decides the internals to export rather than React deciding what to import. On RN's side, a new module named `react-native/Libraries/ReactPrivate/ReactNativePrivateInterface` explicitly exports the modules used by the renderers in this repo. (There is also a private module for InitializeCore so that we can import it just for the side effects.) On React's side, the various renderer modules access RN internals through the explicit private interface. The Rollup configuration becomes slimmer since the only external package is now `react-native`, and the individual modules are instead listed out in `ReactNativePrivateInterface`. Task description: https://github.com/facebook/react-native/issues/24770 Sister RN PR (needs to land before this one): https://github.com/facebook/react-native/pull/24782 Test Plan: Ran unit tests and Flow in this repo. Generated the renderers and manually copied them over to the RN repo. Ran the RN tests and launched the RNTester app. --- .../src/NativeMethodsMixin.js | 6 +- .../src/ReactFabricGlobalResponderHandler.js | 2 +- .../src/ReactFabricHostConfig.js | 26 +- .../src/ReactNativeAttributePayload.js | 6 +- .../src/ReactNativeBridgeEventPlugin.js | 12 +- .../src/ReactNativeComponent.js | 6 +- .../src/ReactNativeFiberHostComponent.js | 6 +- .../src/ReactNativeFiberInspector.js | 2 +- .../src/ReactNativeGlobalResponderHandler.js | 2 +- .../src/ReactNativeHostConfig.js | 10 +- .../src/ReactNativeInjection.js | 2 +- .../src/ReactNativeInjectionShared.js | 2 +- .../src/ReactNativeRenderer.js | 2 +- .../src/ReactNativeRendererSharedExports.js | 2 +- .../Libraries/ReactPrivate}/BatchedBridge.js | 0 .../ReactPrivate}/ExceptionsManager.js | 0 .../ReactPrivate}/FabricUIManager.js | 0 .../Libraries/ReactPrivate}/Platform.js | 0 .../ReactPrivate}/RCTEventEmitter.js | 0 .../ReactNativePrivateInitializeCore.js} | 2 + .../ReactNativePrivateInterface.js | 44 ++++ .../ReactNativeViewConfigRegistry.js | 0 .../Libraries/ReactPrivate}/TextInputState.js | 0 .../Libraries/ReactPrivate}/UIManager.js | 0 .../Libraries/ReactPrivate}/deepDiffer.js | 0 .../deepFreezeAndThrowOnMutationInDev.js | 0 .../Libraries/ReactPrivate}/flattenStyle.js | 0 .../__tests__/ReactFabric-test.internal.js | 10 +- .../ReactFabricAndNative-test.internal.js | 7 +- .../ReactNativeError-test.internal.js | 4 +- .../ReactNativeEvents-test.internal.js | 10 +- .../ReactNativeMount-test.internal.js | 7 +- ...ReactNativeComponentClass-test.internal.js | 4 +- .../src/forks/ReactFiberErrorDialog.native.js | 2 +- scripts/flow/react-native-host-hooks.js | 242 ++++++++---------- scripts/rollup/bundles.js | 56 +--- scripts/rollup/modules.js | 2 +- 37 files changed, 239 insertions(+), 237 deletions(-) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/BatchedBridge.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/ExceptionsManager.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/FabricUIManager.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/Platform.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/RCTEventEmitter.js (100%) rename packages/react-native-renderer/src/__mocks__/{InitializeCore.js => react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js} (93%) create mode 100644 packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/ReactNativeViewConfigRegistry.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/TextInputState.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/UIManager.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/deepDiffer.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/deepFreezeAndThrowOnMutationInDev.js (100%) rename packages/react-native-renderer/src/__mocks__/{ => react-native/Libraries/ReactPrivate}/flattenStyle.js (100%) diff --git a/packages/react-native-renderer/src/NativeMethodsMixin.js b/packages/react-native-renderer/src/NativeMethodsMixin.js index 954003b1b6f8e..a42bf0a0342c1 100644 --- a/packages/react-native-renderer/src/NativeMethodsMixin.js +++ b/packages/react-native-renderer/src/NativeMethodsMixin.js @@ -17,8 +17,10 @@ import type { import invariant from 'shared/invariant'; // Modules provided by RN: -import TextInputState from 'TextInputState'; -import UIManager from 'UIManager'; +import { + TextInputState, + UIManager, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import {create} from './ReactNativeAttributePayload'; import { diff --git a/packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js b/packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js index 14109a9570123..69d0b8ae529c0 100644 --- a/packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js +++ b/packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js @@ -8,7 +8,7 @@ */ // Module provided by RN: -import UIManager from 'UIManager'; +import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; const ReactFabricGlobalResponderHandler = { onChange: function(from: any, to: any, blockNativeResponder: boolean) { diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 9b6c1adf2a32c..b2bc523e05855 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -18,31 +18,37 @@ import type {ReactEventComponentInstance} from 'shared/ReactTypes'; import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; import {create, diff} from './ReactNativeAttributePayload'; -import {get as getViewConfigForType} from 'ReactNativeViewConfigRegistry'; -import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev'; import invariant from 'shared/invariant'; import warningWithoutStack from 'shared/warningWithoutStack'; import {dispatchEvent} from './ReactFabricEventEmitter'; // Modules provided by RN: -import TextInputState from 'TextInputState'; import { + FabricUIManager, + ReactNativeViewConfigRegistry, + TextInputState, + deepFreezeAndThrowOnMutationInDev, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; + +const { createNode, cloneNode, cloneNodeWithNewChildren, cloneNodeWithNewChildrenAndProps, cloneNodeWithNewProps, - createChildSet as createChildNodeSet, - appendChild as appendChildNode, - appendChildToSet as appendChildNodeToSet, + createChildSet: createChildNodeSet, + appendChild: appendChildNode, + appendChildToSet: appendChildNodeToSet, completeRoot, registerEventHandler, - measure as fabricMeasure, - measureInWindow as fabricMeasureInWindow, - measureLayout as fabricMeasureLayout, -} from 'FabricUIManager'; + measure: fabricMeasure, + measureInWindow: fabricMeasureInWindow, + measureLayout: fabricMeasureLayout, +} = FabricUIManager; + +const {get: getViewConfigForType} = ReactNativeViewConfigRegistry; // Counter for uniquely identifying views. // % 10 === 1 means it is a rootTag. diff --git a/packages/react-native-renderer/src/ReactNativeAttributePayload.js b/packages/react-native-renderer/src/ReactNativeAttributePayload.js index 3273b89111aa0..5e6cd4d81533f 100644 --- a/packages/react-native-renderer/src/ReactNativeAttributePayload.js +++ b/packages/react-native-renderer/src/ReactNativeAttributePayload.js @@ -8,8 +8,10 @@ */ // Modules provided by RN: -import deepDiffer from 'deepDiffer'; -import flattenStyle from 'flattenStyle'; +import { + deepDiffer, + flattenStyle, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import type {AttributeConfiguration} from './ReactNativeTypes'; diff --git a/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js b/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js index 237349671f1e9..56f4fe65c557a 100644 --- a/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js +++ b/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js @@ -13,13 +13,17 @@ import { accumulateDirectDispatches, } from 'events/EventPropagators'; import type {TopLevelType} from 'events/TopLevelEventTypes'; -import { +import SyntheticEvent from 'events/SyntheticEvent'; +import invariant from 'shared/invariant'; + +// Module provided by RN: +import {ReactNativeViewConfigRegistry} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; + +const { customBubblingEventTypes, customDirectEventTypes, eventTypes, -} from 'ReactNativeViewConfigRegistry'; -import SyntheticEvent from 'events/SyntheticEvent'; -import invariant from 'shared/invariant'; +} = ReactNativeViewConfigRegistry; const ReactNativeBridgeEventPlugin = { eventTypes: eventTypes, diff --git a/packages/react-native-renderer/src/ReactNativeComponent.js b/packages/react-native-renderer/src/ReactNativeComponent.js index 4986c3cce5eee..b6c3dfb59dee2 100644 --- a/packages/react-native-renderer/src/ReactNativeComponent.js +++ b/packages/react-native-renderer/src/ReactNativeComponent.js @@ -18,8 +18,10 @@ import type { import React from 'react'; // Modules provided by RN: -import TextInputState from 'TextInputState'; -import UIManager from 'UIManager'; +import { + TextInputState, + UIManager, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import {create} from './ReactNativeAttributePayload'; import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; diff --git a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js index 629816fef1c53..02d47c84c030f 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js +++ b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js @@ -17,8 +17,10 @@ import type { import type {Instance} from './ReactNativeHostConfig'; // Modules provided by RN: -import TextInputState from 'TextInputState'; -import UIManager from 'UIManager'; +import { + TextInputState, + UIManager, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import {create} from './ReactNativeAttributePayload'; import { diff --git a/packages/react-native-renderer/src/ReactNativeFiberInspector.js b/packages/react-native-renderer/src/ReactNativeFiberInspector.js index f614b1224a0b7..5693a8edd892d 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberInspector.js +++ b/packages/react-native-renderer/src/ReactNativeFiberInspector.js @@ -17,7 +17,7 @@ import getComponentName from 'shared/getComponentName'; import {HostComponent} from 'shared/ReactWorkTags'; import invariant from 'shared/invariant'; // Module provided by RN: -import UIManager from 'UIManager'; +import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import {getClosestInstanceFromNode} from './ReactNativeComponentTree'; diff --git a/packages/react-native-renderer/src/ReactNativeGlobalResponderHandler.js b/packages/react-native-renderer/src/ReactNativeGlobalResponderHandler.js index 169ec8006d4f0..efb98d8fc24ef 100644 --- a/packages/react-native-renderer/src/ReactNativeGlobalResponderHandler.js +++ b/packages/react-native-renderer/src/ReactNativeGlobalResponderHandler.js @@ -8,7 +8,7 @@ */ // Module provided by RN: -import UIManager from 'UIManager'; +import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; const ReactNativeGlobalResponderHandler = { onChange: function(from: any, to: any, blockNativeResponder: boolean) { diff --git a/packages/react-native-renderer/src/ReactNativeHostConfig.js b/packages/react-native-renderer/src/ReactNativeHostConfig.js index 4b0ac12c2bd5d..80a30a55a69d7 100644 --- a/packages/react-native-renderer/src/ReactNativeHostConfig.js +++ b/packages/react-native-renderer/src/ReactNativeHostConfig.js @@ -13,10 +13,12 @@ import type {ReactEventComponentInstance} from 'shared/ReactTypes'; import invariant from 'shared/invariant'; // Modules provided by RN: -import UIManager from 'UIManager'; -import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev'; +import { + ReactNativeViewConfigRegistry, + UIManager, + deepFreezeAndThrowOnMutationInDev, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; -import {get as getViewConfigForType} from 'ReactNativeViewConfigRegistry'; import {create, diff} from './ReactNativeAttributePayload'; import { precacheFiberNode, @@ -25,6 +27,8 @@ import { } from './ReactNativeComponentTree'; import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent'; +const {get: getViewConfigForType} = ReactNativeViewConfigRegistry; + export type Type = string; export type Props = Object; export type Container = number; diff --git a/packages/react-native-renderer/src/ReactNativeInjection.js b/packages/react-native-renderer/src/ReactNativeInjection.js index e908dc9bc8fbf..3e775c4572c7a 100644 --- a/packages/react-native-renderer/src/ReactNativeInjection.js +++ b/packages/react-native-renderer/src/ReactNativeInjection.js @@ -20,7 +20,7 @@ import ReactNativeGlobalResponderHandler from './ReactNativeGlobalResponderHandl import ResponderEventPlugin from 'events/ResponderEventPlugin'; // Module provided by RN: -import RCTEventEmitter from 'RCTEventEmitter'; +import {RCTEventEmitter} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; /** * Register the event emitter with the native bridge diff --git a/packages/react-native-renderer/src/ReactNativeInjectionShared.js b/packages/react-native-renderer/src/ReactNativeInjectionShared.js index ccb61f80e051b..a8861d3589bf5 100644 --- a/packages/react-native-renderer/src/ReactNativeInjectionShared.js +++ b/packages/react-native-renderer/src/ReactNativeInjectionShared.js @@ -14,7 +14,7 @@ * TODO: require this in packager, not in React #10932517 */ // Module provided by RN: -import 'InitializeCore'; +import 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore'; import {injection as EventPluginHubInjection} from 'events/EventPluginHub'; import ResponderEventPlugin from 'events/ResponderEventPlugin'; diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 3d27d25c0ae23..7c333f8148fbc 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -33,7 +33,7 @@ import { } from 'events/ReactGenericBatching'; import ReactVersion from 'shared/ReactVersion'; // Module provided by RN: -import UIManager from 'UIManager'; +import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import NativeMethodsMixin from './NativeMethodsMixin'; import ReactNativeComponent from './ReactNativeComponent'; diff --git a/packages/react-native-renderer/src/ReactNativeRendererSharedExports.js b/packages/react-native-renderer/src/ReactNativeRendererSharedExports.js index 91ddf9ed88e79..f79f4d087c1ab 100644 --- a/packages/react-native-renderer/src/ReactNativeRendererSharedExports.js +++ b/packages/react-native-renderer/src/ReactNativeRendererSharedExports.js @@ -13,7 +13,7 @@ import {warnForStyleProps} from './NativeMethodsMixinUtils'; import warningWithoutStack from 'shared/warningWithoutStack'; // Module provided by RN: -import UIManager from 'UIManager'; +import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; export function setNativeProps(handle: any, nativeProps: Object): void { if (handle._nativeTag == null) { diff --git a/packages/react-native-renderer/src/__mocks__/BatchedBridge.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/BatchedBridge.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/BatchedBridge.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/BatchedBridge.js diff --git a/packages/react-native-renderer/src/__mocks__/ExceptionsManager.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ExceptionsManager.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/ExceptionsManager.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ExceptionsManager.js diff --git a/packages/react-native-renderer/src/__mocks__/FabricUIManager.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/FabricUIManager.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/FabricUIManager.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/FabricUIManager.js diff --git a/packages/react-native-renderer/src/__mocks__/Platform.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/Platform.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/Platform.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/Platform.js diff --git a/packages/react-native-renderer/src/__mocks__/RCTEventEmitter.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/RCTEventEmitter.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/RCTEventEmitter.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/RCTEventEmitter.js diff --git a/packages/react-native-renderer/src/__mocks__/InitializeCore.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js similarity index 93% rename from packages/react-native-renderer/src/__mocks__/InitializeCore.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js index 0a7415c017ecb..1e2b976896799 100644 --- a/packages/react-native-renderer/src/__mocks__/InitializeCore.js +++ b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @flow strict */ 'use strict'; diff --git a/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js new file mode 100644 index 0000000000000..e07239520b04c --- /dev/null +++ b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js @@ -0,0 +1,44 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + */ + +module.exports = { + get BatchedBridge() { + return require('./BatchedBridge.js'); + }, + get ExceptionsManager() { + return require('./ExceptionsManager'); + }, + get Platform() { + return require('./Platform'); + }, + get FabricUIManager() { + return require('./FabricUIManager'); + }, + get RCTEventEmitter() { + return require('./RCTEventEmitter'); + }, + get ReactNativeViewConfigRegistry() { + return require('./ReactNativeViewConfigRegistry'); + }, + get TextInputState() { + return require('./TextInputState'); + }, + get UIManager() { + return require('./UIManager'); + }, + get deepDiffer() { + return require('./deepDiffer'); + }, + get deepFreezeAndThrowOnMutationInDev() { + return require('./deepFreezeAndThrowOnMutationInDev'); + }, + get flattenStyle() { + return require('./flattenStyle'); + }, +}; diff --git a/packages/react-native-renderer/src/__mocks__/ReactNativeViewConfigRegistry.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativeViewConfigRegistry.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/ReactNativeViewConfigRegistry.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativeViewConfigRegistry.js diff --git a/packages/react-native-renderer/src/__mocks__/TextInputState.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/TextInputState.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/TextInputState.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/TextInputState.js diff --git a/packages/react-native-renderer/src/__mocks__/UIManager.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/UIManager.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/UIManager.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/UIManager.js diff --git a/packages/react-native-renderer/src/__mocks__/deepDiffer.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/deepDiffer.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/deepDiffer.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/deepDiffer.js diff --git a/packages/react-native-renderer/src/__mocks__/deepFreezeAndThrowOnMutationInDev.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/deepFreezeAndThrowOnMutationInDev.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/deepFreezeAndThrowOnMutationInDev.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/deepFreezeAndThrowOnMutationInDev.js diff --git a/packages/react-native-renderer/src/__mocks__/flattenStyle.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/flattenStyle.js similarity index 100% rename from packages/react-native-renderer/src/__mocks__/flattenStyle.js rename to packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/flattenStyle.js diff --git a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js index e95402967a9fa..447adeedcbafc 100644 --- a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js @@ -36,15 +36,17 @@ describe('ReactFabric', () => { ReactFeatureFlags = require('shared/ReactFeatureFlags'); ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true; ReactFabric = require('react-native-renderer/fabric'); - FabricUIManager = require('FabricUIManager'); - UIManager = require('UIManager'); + FabricUIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .FabricUIManager; + UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .UIManager; createReactClass = require('create-react-class/factory')( React.Component, React.isValidElement, new React.Component().updater, ); - createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') - .register; + createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .ReactNativeViewConfigRegistry.register; NativeMethodsMixin = ReactFabric.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED .NativeMethodsMixin; diff --git a/packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js index 1fff126bb1bba..74bd6e05f8d7c 100644 --- a/packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js @@ -20,16 +20,17 @@ describe('ReactFabric', () => { beforeEach(() => { jest.resetModules(); ReactNative = require('react-native-renderer'); - UIManager = require('UIManager'); jest.resetModules(); + UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .UIManager; jest.mock('shared/ReactFeatureFlags', () => require('shared/forks/ReactFeatureFlags.native-oss'), ); React = require('react'); ReactFabric = require('react-native-renderer/fabric'); - createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') - .register; + createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .ReactNativeViewConfigRegistry.register; }); it('find Fabric nodes with the RN renderer', () => { diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js index f688d07a68b52..9abf0ee21aecb 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js @@ -25,8 +25,8 @@ describe('ReactNativeError', () => { React = require('react'); ReactNative = require('react-native-renderer'); - createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') - .register; + createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .ReactNativeViewConfigRegistry.register; computeComponentStackForErrorReporting = ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED .computeComponentStackForErrorReporting; diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js index 5378e80e4fc3c..e9de5541a3af0 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js @@ -64,13 +64,15 @@ beforeEach(() => { jest.resetModules(); PropTypes = require('prop-types'); - RCTEventEmitter = require('RCTEventEmitter'); + RCTEventEmitter = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .RCTEventEmitter; React = require('react'); ReactNative = require('react-native-renderer'); ResponderEventPlugin = require('events/ResponderEventPlugin').default; - UIManager = require('UIManager'); - createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') - .register; + UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .UIManager; + createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .ReactNativeViewConfigRegistry.register; }); it('fails if unknown/unsupported event types are dispatched', () => { diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js index 67ccf4fc0c7fe..8d3f0bb28954b 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js @@ -34,14 +34,15 @@ describe('ReactNative', () => { ReactFeatureFlags = require('shared/ReactFeatureFlags'); ReactFeatureFlags.warnAboutDeprecatedSetNativeProps = true; ReactNative = require('react-native-renderer'); - UIManager = require('UIManager'); + UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .UIManager; createReactClass = require('create-react-class/factory')( React.Component, React.isValidElement, new React.Component().updater, ); - createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') - .register; + createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .ReactNativeViewConfigRegistry.register; NativeMethodsMixin = ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED .NativeMethodsMixin; diff --git a/packages/react-native-renderer/src/__tests__/createReactNativeComponentClass-test.internal.js b/packages/react-native-renderer/src/__tests__/createReactNativeComponentClass-test.internal.js index c53282997cc00..e0e5ad6b4e791 100644 --- a/packages/react-native-renderer/src/__tests__/createReactNativeComponentClass-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/createReactNativeComponentClass-test.internal.js @@ -18,8 +18,8 @@ describe('createReactNativeComponentClass', () => { beforeEach(() => { jest.resetModules(); - createReactNativeComponentClass = require('ReactNativeViewConfigRegistry') - .register; + createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') + .ReactNativeViewConfigRegistry.register; React = require('react'); ReactNative = require('react-native-renderer'); }); diff --git a/packages/react-reconciler/src/forks/ReactFiberErrorDialog.native.js b/packages/react-reconciler/src/forks/ReactFiberErrorDialog.native.js index 28130e81badf4..e5f0cf4db19bd 100644 --- a/packages/react-reconciler/src/forks/ReactFiberErrorDialog.native.js +++ b/packages/react-reconciler/src/forks/ReactFiberErrorDialog.native.js @@ -10,7 +10,7 @@ import type {CapturedError} from '../ReactCapturedValue'; // Module provided by RN: -import ExceptionsManager from 'ExceptionsManager'; +import {ExceptionsManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; /** * Intercept lifecycle errors and ensure they are shown with the correct stack diff --git a/scripts/flow/react-native-host-hooks.js b/scripts/flow/react-native-host-hooks.js index 2753d1e2fdbe6..9a6a0f0fffbdb 100644 --- a/scripts/flow/react-native-host-hooks.js +++ b/scripts/flow/react-native-host-hooks.js @@ -18,130 +18,119 @@ import type { } from 'react-native-renderer/src/ReactNativeTypes'; import type {RNTopLevelEventType} from 'events/TopLevelEventTypes'; -declare module 'deepDiffer' { - declare module.exports: (one: any, two: any) => boolean; -} -declare module 'deepFreezeAndThrowOnMutationInDev' { - declare module.exports: (obj: T) => T; -} -declare module 'flattenStyle' { -} -declare module 'InitializeCore' { -} -declare module 'RCTEventEmitter' { - declare function register(mixed): void; -} -declare module 'TextInputState' { - declare function blurTextInput(object: any): void; - declare function focusTextInput(object: any): void; -} -declare module 'ExceptionsManager' { - declare function handleException(error: Error, isFatal: boolean): void; -} -declare module 'Platform' { - declare var OS: string; -} -declare module 'UIManager' { - declare var customBubblingEventTypes: Object; - declare var customDirectEventTypes: Object; - declare function createView( - reactTag: number, - viewName: string, - rootTag: number, - props: ?Object, - ): void; - declare function manageChildren( - containerTag: number, - moveFromIndices: Array, - moveToIndices: Array, - addChildReactTags: Array, - addAtIndices: Array, - removeAtIndices: Array, - ): void; - declare function measure(hostComponent: mixed, callback: Function): void; - declare function measureInWindow( - nativeTag: ?number, - callback: Function, - ): void; - declare function measureLayout( - nativeTag: mixed, - nativeNode: number, - onFail: Function, - onSuccess: Function, - ): void; - declare function removeRootView(containerTag: number): void; - declare function removeSubviewsFromContainerWithID(containerId: number): void; - declare function replaceExistingNonRootView(): void; - declare function setChildren( - containerTag: number, - reactTags: Array, - ): void; - declare function updateView( - reactTag: number, - viewName: string, - props: ?Object, - ): void; - declare function __takeSnapshot( - view?: 'window' | Element | number, - options?: { - width?: number, - height?: number, - format?: 'png' | 'jpeg', - quality?: number, - }, - ): Promise; - declare function setJSResponder( - reactTag: number, - blockNativeResponder: boolean, - ): void; - declare function clearJSResponder(): void; -} +declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' { + declare export function deepDiffer(one: any, two: any): boolean; + declare export function deepFreezeAndThrowOnMutationInDev(obj: T): T; + declare export function flattenStyle(style: any): any; + declare export var RCTEventEmitter: { + register: (eventEmitter: mixed) => void, + }; + declare export var TextInputState: { + blurTextInput: (object: any) => void, + focusTextInput: (object: any) => void, + }; + declare export var ExceptionsManager: { + handleException: (error: Error, isFatal: boolean) => void, + }; + declare export var Platform: { + OS: string, + }; + declare export var UIManager: { + customBubblingEventTypes: Object, + customDirectEventTypes: Object, + createView: ( + reactTag: number, + viewName: string, + rootTag: number, + props: ?Object, + ) => void, + manageChildren: ( + containerTag: number, + moveFromIndices: Array, + moveToIndices: Array, + addChildReactTags: Array, + addAtIndices: Array, + removeAtIndices: Array, + ) => void, + measure: (hostComponent: mixed, callback: Function) => void, + measureInWindow: (nativeTag: ?number, callback: Function) => void, + measureLayout: ( + nativeTag: mixed, + nativeNode: number, + onFail: Function, + onSuccess: Function, + ) => void, + removeRootView: (containerTag: number) => void, + removeSubviewsFromContainerWithID: (containerId: number) => void, + replaceExistingNonRootView: () => void, + setChildren: (containerTag: number, reactTags: Array) => void, + updateView: (reactTag: number, viewName: string, props: ?Object) => void, + __takeSnapshot: ( + view?: 'window' | Element | number, + options?: { + width?: number, + height?: number, + format?: 'png' | 'jpeg', + quality?: number, + }, + ) => Promise, + setJSResponder: (reactTag: number, blockNativeResponder: boolean) => void, + clearJSResponder: () => void, + }; + declare export var FabricUIManager: { + createNode: ( + reactTag: number, + viewName: string, + rootTag: number, + props: ?Object, + eventTarget: Object, + ) => Object, + cloneNode: (node: Object) => Object, + cloneNodeWithNewChildren: (node: Object) => Object, + cloneNodeWithNewProps: (node: Object, newProps: ?Object) => Object, + cloneNodeWithNewChildrenAndProps: ( + node: Object, + newProps: ?Object, + ) => Object, + appendChild: (node: Object, childNode: Object) => void, -declare module 'FabricUIManager' { - declare function createNode( - reactTag: number, - viewName: string, - rootTag: number, - props: ?Object, - eventTarget: Object, - ): Object; - declare function cloneNode(node: Object): Object; - declare function cloneNodeWithNewChildren(node: Object): Object; - declare function cloneNodeWithNewProps( - node: Object, - newProps: ?Object, - ): Object; - declare function cloneNodeWithNewChildrenAndProps( - node: Object, - newProps: ?Object, - ): Object; - declare function appendChild(node: Object, childNode: Object): void; + createChildSet: (rootTag: number) => Object, + appendChildToSet: (childSet: Object, childNode: Object) => void, + completeRoot: (rootTag: number, childSet: Object) => void, + registerEventHandler: ( + callback: ( + eventTarget: null | Object, + type: RNTopLevelEventType, + payload: Object, + ) => void, + ) => void, - declare function createChildSet(rootTag: number): Object; - declare function appendChildToSet(childSet: Object, childNode: Object): void; - declare function completeRoot(rootTag: number, childSet: Object): void; - declare function registerEventHandler( - callback: ( - eventTarget: null | Object, - type: RNTopLevelEventType, - payload: Object, + measure: (node: Node, callback: MeasureOnSuccessCallback) => void, + measureInWindow: ( + node: Node, + callback: MeasureInWindowOnSuccessCallback, ) => void, - ): void; + measureLayout: ( + node: Node, + relativeNode: Node, + onFail: () => void, + onSuccess: MeasureLayoutOnSuccessCallback, + ) => void, + }; + declare export var BatchedBridge: { + registerCallableModule: (name: string, module: Object) => void, + }; + declare export var ReactNativeViewConfigRegistry: { + customBubblingEventTypes: Object, + customDirectEventTypes: Object, + eventTypes: Object, - declare function measure( - node: Node, - callback: MeasureOnSuccessCallback, - ): void; - declare function measureInWindow( - node: Node, - callback: MeasureInWindowOnSuccessCallback, - ): void; - declare function measureLayout( - node: Node, - relativeNode: Node, - onFail: () => void, - onSuccess: MeasureLayoutOnSuccessCallback, - ): void; + register: (name: string, callback: ViewConfigGetter) => string, + get: (name: string) => ReactNativeBaseComponentViewConfig, + }; +} + +declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore' { } // This is needed for a short term solution. @@ -175,16 +164,3 @@ declare module 'RTManager' { declare function completeUpdates(): void; } - -declare module 'BatchedBridge' { - declare function registerCallableModule(name: string, module: Object): void; -} - -declare module 'ReactNativeViewConfigRegistry' { - declare var customBubblingEventTypes: Object; - declare var customDirectEventTypes: Object; - declare var eventTypes: Object; - - declare function register(name: string, callback: ViewConfigGetter): string; - declare function get(name: string): ReactNativeBaseComponentViewConfig; -} diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index a5c802674af55..90dc854186978 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -204,38 +204,14 @@ const bundles = [ moduleType: RENDERER, entry: 'react-native-renderer', global: 'ReactNativeRenderer', - externals: [ - 'ExceptionsManager', - 'InitializeCore', - 'Platform', - 'RCTEventEmitter', - 'TextInputState', - 'UIManager', - 'FabricUIManager', - 'deepDiffer', - 'deepFreezeAndThrowOnMutationInDev', - 'flattenStyle', - 'ReactNativeViewConfigRegistry', - ], + externals: ['react-native'], }, { bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING], moduleType: RENDERER, entry: 'react-native-renderer', global: 'ReactNativeRenderer', - externals: [ - 'ExceptionsManager', - 'InitializeCore', - 'Platform', - 'RCTEventEmitter', - 'TextInputState', - 'UIManager', - 'FabricUIManager', - 'deepDiffer', - 'deepFreezeAndThrowOnMutationInDev', - 'flattenStyle', - 'ReactNativeViewConfigRegistry', - ], + externals: ['react-native'], }, /******* React Native Fabric *******/ @@ -244,38 +220,14 @@ const bundles = [ moduleType: RENDERER, entry: 'react-native-renderer/fabric', global: 'ReactFabric', - externals: [ - 'ExceptionsManager', - 'InitializeCore', - 'Platform', - 'RCTEventEmitter', - 'TextInputState', - 'UIManager', - 'FabricUIManager', - 'deepDiffer', - 'deepFreezeAndThrowOnMutationInDev', - 'flattenStyle', - 'ReactNativeViewConfigRegistry', - ], + externals: ['react-native'], }, { bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING], moduleType: RENDERER, entry: 'react-native-renderer/fabric', global: 'ReactFabric', - externals: [ - 'ExceptionsManager', - 'InitializeCore', - 'Platform', - 'RCTEventEmitter', - 'TextInputState', - 'UIManager', - 'FabricUIManager', - 'deepDiffer', - 'deepFreezeAndThrowOnMutationInDev', - 'flattenStyle', - 'ReactNativeViewConfigRegistry', - ], + externals: ['react-native'], }, /******* React Test Renderer *******/ diff --git a/scripts/rollup/modules.js b/scripts/rollup/modules.js index 4134b776616c9..e6b17d0b9be85 100644 --- a/scripts/rollup/modules.js +++ b/scripts/rollup/modules.js @@ -14,7 +14,7 @@ const HAS_NO_SIDE_EFFECTS_ON_IMPORT = false; // const HAS_SIDE_EFFECTS_ON_IMPORT = true; const importSideEffects = Object.freeze({ 'prop-types/checkPropTypes': HAS_NO_SIDE_EFFECTS_ON_IMPORT, - deepFreezeAndThrowOnMutationInDev: HAS_NO_SIDE_EFFECTS_ON_IMPORT, + 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface': HAS_NO_SIDE_EFFECTS_ON_IMPORT, scheduler: HAS_NO_SIDE_EFFECTS_ON_IMPORT, 'scheduler/tracing': HAS_NO_SIDE_EFFECTS_ON_IMPORT, });