mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
21d0c11523
* Update transforms to handle ES modules
* Update Jest to handle ES modules
* Convert react package to ES modules
* Convert react-art package to ES Modules
* Convert react-call-return package to ES Modules
* Convert react-test-renderer package to ES Modules
* Convert react-cs-renderer package to ES Modules
* Convert react-rt-renderer package to ES Modules
* Convert react-noop-renderer package to ES Modules
* Convert react-dom/server to ES modules
* Convert react-dom/{client,events,test-utils} to ES modules
* Convert react-dom/shared to ES modules
* Convert react-native-renderer to ES modules
* Convert react-reconciler to ES modules
* Convert events to ES modules
* Convert shared to ES modules
* Remove CommonJS support from transforms
* Move ReactDOMFB entry point code into react-dom/src
This is clearer because we can use ES imports in it.
* Fix Rollup shim configuration to work with ESM
* Fix incorrect comment
* Exclude external imports without side effects
* Fix ReactDOM FB build
* Remove TODOs I don’t intend to fix yet
146 lines
5.0 KiB
JavaScript
146 lines
5.0 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {ReactNativeType} from './ReactNativeTypes';
|
|
import type {ReactNodeList} from 'shared/ReactTypes';
|
|
|
|
import './ReactNativeInjection';
|
|
|
|
// TODO: direct imports like some-package/src/* are bad. Fix me.
|
|
import * as ReactFiberErrorLogger
|
|
from 'react-reconciler/src/ReactFiberErrorLogger';
|
|
import * as ReactPortal from 'react-reconciler/src/ReactPortal';
|
|
import {injectInternals} from 'react-reconciler/src/ReactFiberDevToolsHook';
|
|
import ReactGenericBatching from 'events/ReactGenericBatching';
|
|
import TouchHistoryMath from 'events/TouchHistoryMath';
|
|
import * as ReactGlobalSharedState from 'shared/ReactGlobalSharedState';
|
|
import ReactVersion from 'shared/ReactVersion';
|
|
// Module provided by RN:
|
|
import UIManager from 'UIManager';
|
|
|
|
import {showDialog} from './ReactNativeFiberErrorDialog';
|
|
import NativeMethodsMixin from './NativeMethodsMixin';
|
|
import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
|
|
import ReactNativeComponent from './ReactNativeComponent';
|
|
import ReactNativeComponentTree from './ReactNativeComponentTree';
|
|
import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
|
|
import ReactNativePropRegistry from './ReactNativePropRegistry';
|
|
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
|
|
import createReactNativeComponentClass from './createReactNativeComponentClass';
|
|
import findNumericNodeHandle from './findNumericNodeHandle';
|
|
import takeSnapshot from './takeSnapshot';
|
|
|
|
ReactGenericBatching.injection.injectFiberBatchedUpdates(
|
|
ReactNativeFiberRenderer.batchedUpdates,
|
|
);
|
|
|
|
const roots = new Map();
|
|
|
|
// Intercept lifecycle errors and ensure they are shown with the correct stack
|
|
// trace within the native redbox component.
|
|
ReactFiberErrorLogger.injection.injectDialog(showDialog);
|
|
|
|
const ReactNativeRenderer: ReactNativeType = {
|
|
NativeComponent: ReactNativeComponent,
|
|
|
|
findNodeHandle: findNumericNodeHandle,
|
|
|
|
render(element: React$Element<any>, containerTag: any, callback: ?Function) {
|
|
let root = roots.get(containerTag);
|
|
|
|
if (!root) {
|
|
// TODO (bvaughn): If we decide to keep the wrapper component,
|
|
// We could create a wrapper for containerTag as well to reduce special casing.
|
|
root = ReactNativeFiberRenderer.createContainer(containerTag, false);
|
|
roots.set(containerTag, root);
|
|
}
|
|
ReactNativeFiberRenderer.updateContainer(element, root, null, callback);
|
|
|
|
return ReactNativeFiberRenderer.getPublicRootInstance(root);
|
|
},
|
|
|
|
unmountComponentAtNode(containerTag: number) {
|
|
const root = roots.get(containerTag);
|
|
if (root) {
|
|
// TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
|
|
ReactNativeFiberRenderer.updateContainer(null, root, null, () => {
|
|
roots.delete(containerTag);
|
|
});
|
|
}
|
|
},
|
|
|
|
unmountComponentAtNodeAndRemoveContainer(containerTag: number) {
|
|
ReactNativeRenderer.unmountComponentAtNode(containerTag);
|
|
|
|
// Call back into native to remove all of the subviews from this container
|
|
UIManager.removeRootView(containerTag);
|
|
},
|
|
|
|
createPortal(
|
|
children: ReactNodeList,
|
|
containerTag: number,
|
|
key: ?string = null,
|
|
) {
|
|
return ReactPortal.createPortal(children, containerTag, null, key);
|
|
},
|
|
|
|
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
|
|
|
|
flushSync: ReactNativeFiberRenderer.flushSync,
|
|
|
|
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
|
|
// Used as a mixin in many createClass-based components
|
|
NativeMethodsMixin,
|
|
// Used by react-native-github/Libraries/ components
|
|
ReactNativeBridgeEventPlugin, // requireNativeComponent
|
|
ReactGlobalSharedState, // Systrace
|
|
ReactNativeComponentTree, // InspectorUtils, ScrollResponder
|
|
ReactNativePropRegistry, // flattenStyle, Stylesheet
|
|
TouchHistoryMath, // PanResponder
|
|
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
|
|
takeSnapshot, // react-native-implementation
|
|
},
|
|
};
|
|
|
|
if (__DEV__) {
|
|
// $FlowFixMe
|
|
Object.assign(
|
|
ReactNativeRenderer.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
|
{
|
|
// TODO: none of these work since Fiber. Remove these dependencies.
|
|
// Used by RCTRenderingPerf, Systrace:
|
|
ReactDebugTool: {
|
|
addHook() {},
|
|
removeHook() {},
|
|
},
|
|
// Used by ReactPerfStallHandler, RCTRenderingPerf:
|
|
ReactPerf: {
|
|
start() {},
|
|
stop() {},
|
|
printInclusive() {},
|
|
printWasted() {},
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
injectInternals({
|
|
findFiberByHostInstance: ReactNativeComponentTree.getClosestInstanceFromNode,
|
|
findHostInstanceByFiber: ReactNativeFiberRenderer.findHostInstance,
|
|
getInspectorDataForViewTag: getInspectorDataForViewTag,
|
|
// This is an enum because we may add more (e.g. profiler build)
|
|
bundleType: __DEV__ ? 1 : 0,
|
|
version: ReactVersion,
|
|
rendererPackageName: 'react-native-renderer',
|
|
});
|
|
|
|
export default ReactNativeRenderer;
|