2016-12-08 10:15:13 +08:00
|
|
|
/**
|
2017-09-25 04:48:13 +08:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
2016-12-08 10:15:13 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-12-08 10:15:13 +08:00
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
2017-10-26 02:07:54 +08:00
|
|
|
import type {ReactNativeType} from './ReactNativeTypes';
|
|
|
|
|
import type {ReactNodeList} from 'shared/ReactTypes';
|
|
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
import './ReactNativeInjection';
|
2017-10-26 02:07:54 +08:00
|
|
|
|
2017-10-25 07:55:00 +08:00
|
|
|
// TODO: direct imports like some-package/src/* are bad. Fix me.
|
2017-11-03 03:50:03 +08:00
|
|
|
import * as ReactFiberErrorLogger
|
|
|
|
|
from 'react-reconciler/src/ReactFiberErrorLogger';
|
|
|
|
|
import * as ReactPortal from 'react-reconciler/src/ReactPortal';
|
|
|
|
|
import {injectInternals} from 'react-reconciler/src/ReactFiberDevToolsHook';
|
2017-11-05 19:58:36 +08:00
|
|
|
import * as ReactGenericBatching from 'events/ReactGenericBatching';
|
2017-11-03 03:50:03 +08:00
|
|
|
import TouchHistoryMath from 'events/TouchHistoryMath';
|
|
|
|
|
import * as ReactGlobalSharedState from 'shared/ReactGlobalSharedState';
|
|
|
|
|
import ReactVersion from 'shared/ReactVersion';
|
2017-10-25 07:55:00 +08:00
|
|
|
// Module provided by RN:
|
2017-11-03 03:50:03 +08:00
|
|
|
import UIManager from 'UIManager';
|
|
|
|
|
|
|
|
|
|
import {showDialog} from './ReactNativeFiberErrorDialog';
|
|
|
|
|
import NativeMethodsMixin from './NativeMethodsMixin';
|
|
|
|
|
import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
|
|
|
|
|
import ReactNativeComponent from './ReactNativeComponent';
|
2017-11-05 19:58:36 +08:00
|
|
|
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
|
2017-11-03 03:50:03 +08:00
|
|
|
import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
|
|
|
|
|
import ReactNativePropRegistry from './ReactNativePropRegistry';
|
|
|
|
|
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
|
|
|
|
|
import createReactNativeComponentClass from './createReactNativeComponentClass';
|
|
|
|
|
import findNumericNodeHandle from './findNumericNodeHandle';
|
|
|
|
|
import takeSnapshot from './takeSnapshot';
|
2016-12-08 10:15:13 +08:00
|
|
|
|
|
|
|
|
ReactGenericBatching.injection.injectFiberBatchedUpdates(
|
2017-05-25 00:06:30 +08:00
|
|
|
ReactNativeFiberRenderer.batchedUpdates,
|
2016-12-08 10:15:13 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const roots = new Map();
|
|
|
|
|
|
2017-03-31 06:15:33 +08:00
|
|
|
// Intercept lifecycle errors and ensure they are shown with the correct stack
|
|
|
|
|
// trace within the native redbox component.
|
2017-11-03 03:50:03 +08:00
|
|
|
ReactFiberErrorLogger.injection.injectDialog(showDialog);
|
2017-03-31 06:15:33 +08:00
|
|
|
|
Reorganize code structure (#11288)
* Move files and tests to more meaningful places
* Fix the build
Now that we import reconciler via react-reconciler, I needed to make a few tweaks.
* Update sizes
* Move @preventMunge directive to FB header
* Revert unintentional change
* Fix Flow coverage
I forgot to @flow-ify those files. This uncovered some issues.
* Prettier, I love you but you're bringing me down
Prettier, I love you but you're bringing me down
Like a rat in a cage
Pulling minimum wage
Prettier, I love you but you're bringing me down
Prettier, you're safer and you're wasting my time
Our records all show you were filthy but fine
But they shuttered your stores
When you opened the doors
To the cops who were bored once they'd run out of crime
Prettier, you're perfect, oh, please don't change a thing
Your mild billionaire mayor's now convinced he's a king
So the boring collect
I mean all disrespect
In the neighborhood bars I'd once dreamt I would drink
Prettier, I love you but you're freaking me out
There's a ton of the twist but we're fresh out of shout
Like a death in the hall
That you hear through your wall
Prettier, I love you but you're freaking me out
Prettier, I love you but you're bringing me down
Prettier, I love you but you're bringing me down
Like a death of the heart
Jesus, where do I start?
But you're still the one pool where I'd happily drown
And oh! Take me off your mailing list
For kids who think it still exists
Yes, for those who think it still exists
Maybe I'm wrong and maybe you're right
Maybe I'm wrong and maybe you're right
Maybe you're right, maybe I'm wrong
And just maybe you're right
And oh! Maybe mother told you true
And there'll always be somebody there for you
And you'll never be alone
But maybe she's wrong and maybe I'm right
And just maybe she's wrong
Maybe she's wrong and maybe I'm right
And if so, here's this song!
2017-10-20 02:50:24 +08:00
|
|
|
const ReactNativeRenderer: ReactNativeType = {
|
2017-11-03 03:50:03 +08:00
|
|
|
NativeComponent: ReactNativeComponent,
|
2017-05-31 12:55:24 +08:00
|
|
|
|
2017-05-25 00:06:30 +08:00
|
|
|
findNodeHandle: findNumericNodeHandle,
|
2016-12-08 10:15:13 +08:00
|
|
|
|
2017-08-29 05:39:58 +08:00
|
|
|
render(element: React$Element<any>, containerTag: any, callback: ?Function) {
|
2016-12-08 10:15:13 +08:00
|
|
|
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.
|
2017-10-14 11:08:36 +08:00
|
|
|
root = ReactNativeFiberRenderer.createContainer(containerTag, false);
|
2016-12-08 10:15:13 +08:00
|
|
|
roots.set(containerTag, root);
|
|
|
|
|
}
|
2017-05-25 00:06:30 +08:00
|
|
|
ReactNativeFiberRenderer.updateContainer(element, root, null, callback);
|
2016-12-08 10:15:13 +08:00
|
|
|
|
2017-05-25 00:06:30 +08:00
|
|
|
return ReactNativeFiberRenderer.getPublicRootInstance(root);
|
2016-12-08 10:15:13 +08:00
|
|
|
},
|
|
|
|
|
|
2017-03-14 08:05:18 +08:00
|
|
|
unmountComponentAtNode(containerTag: number) {
|
2016-12-08 10:15:13 +08:00
|
|
|
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?
|
2017-05-25 00:06:30 +08:00
|
|
|
ReactNativeFiberRenderer.updateContainer(null, root, null, () => {
|
2016-12-17 10:31:39 +08:00
|
|
|
roots.delete(containerTag);
|
|
|
|
|
});
|
2016-12-08 10:15:13 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
unmountComponentAtNodeAndRemoveContainer(containerTag: number) {
|
Reorganize code structure (#11288)
* Move files and tests to more meaningful places
* Fix the build
Now that we import reconciler via react-reconciler, I needed to make a few tweaks.
* Update sizes
* Move @preventMunge directive to FB header
* Revert unintentional change
* Fix Flow coverage
I forgot to @flow-ify those files. This uncovered some issues.
* Prettier, I love you but you're bringing me down
Prettier, I love you but you're bringing me down
Like a rat in a cage
Pulling minimum wage
Prettier, I love you but you're bringing me down
Prettier, you're safer and you're wasting my time
Our records all show you were filthy but fine
But they shuttered your stores
When you opened the doors
To the cops who were bored once they'd run out of crime
Prettier, you're perfect, oh, please don't change a thing
Your mild billionaire mayor's now convinced he's a king
So the boring collect
I mean all disrespect
In the neighborhood bars I'd once dreamt I would drink
Prettier, I love you but you're freaking me out
There's a ton of the twist but we're fresh out of shout
Like a death in the hall
That you hear through your wall
Prettier, I love you but you're freaking me out
Prettier, I love you but you're bringing me down
Prettier, I love you but you're bringing me down
Like a death of the heart
Jesus, where do I start?
But you're still the one pool where I'd happily drown
And oh! Take me off your mailing list
For kids who think it still exists
Yes, for those who think it still exists
Maybe I'm wrong and maybe you're right
Maybe I'm wrong and maybe you're right
Maybe you're right, maybe I'm wrong
And just maybe you're right
And oh! Maybe mother told you true
And there'll always be somebody there for you
And you'll never be alone
But maybe she's wrong and maybe I'm right
And just maybe she's wrong
Maybe she's wrong and maybe I'm right
And if so, here's this song!
2017-10-20 02:50:24 +08:00
|
|
|
ReactNativeRenderer.unmountComponentAtNode(containerTag);
|
2016-12-08 10:15:13 +08:00
|
|
|
|
|
|
|
|
// Call back into native to remove all of the subviews from this container
|
|
|
|
|
UIManager.removeRootView(containerTag);
|
|
|
|
|
},
|
|
|
|
|
|
2017-09-12 05:23:54 +08:00
|
|
|
createPortal(
|
2017-03-14 08:05:18 +08:00
|
|
|
children: ReactNodeList,
|
|
|
|
|
containerTag: number,
|
|
|
|
|
key: ?string = null,
|
|
|
|
|
) {
|
2016-12-08 10:15:13 +08:00
|
|
|
return ReactPortal.createPortal(children, containerTag, null, key);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
|
2017-05-25 00:06:30 +08:00
|
|
|
|
2017-07-22 04:22:11 +08:00
|
|
|
flushSync: ReactNativeFiberRenderer.flushSync,
|
|
|
|
|
|
2017-05-25 00:06:30 +08:00
|
|
|
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
|
|
|
|
|
// Used as a mixin in many createClass-based components
|
2017-11-03 03:50:03 +08:00
|
|
|
NativeMethodsMixin,
|
2017-05-25 00:06:30 +08:00
|
|
|
// Used by react-native-github/Libraries/ components
|
2017-11-03 03:50:03 +08:00
|
|
|
ReactNativeBridgeEventPlugin, // requireNativeComponent
|
|
|
|
|
ReactGlobalSharedState, // Systrace
|
|
|
|
|
ReactNativeComponentTree, // InspectorUtils, ScrollResponder
|
|
|
|
|
ReactNativePropRegistry, // flattenStyle, Stylesheet
|
|
|
|
|
TouchHistoryMath, // PanResponder
|
|
|
|
|
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
|
|
|
|
|
takeSnapshot, // react-native-implementation
|
2017-05-25 00:06:30 +08:00
|
|
|
},
|
2016-12-08 10:15:13 +08:00
|
|
|
};
|
|
|
|
|
|
2017-05-25 00:06:30 +08:00
|
|
|
if (__DEV__) {
|
|
|
|
|
// $FlowFixMe
|
|
|
|
|
Object.assign(
|
Reorganize code structure (#11288)
* Move files and tests to more meaningful places
* Fix the build
Now that we import reconciler via react-reconciler, I needed to make a few tweaks.
* Update sizes
* Move @preventMunge directive to FB header
* Revert unintentional change
* Fix Flow coverage
I forgot to @flow-ify those files. This uncovered some issues.
* Prettier, I love you but you're bringing me down
Prettier, I love you but you're bringing me down
Like a rat in a cage
Pulling minimum wage
Prettier, I love you but you're bringing me down
Prettier, you're safer and you're wasting my time
Our records all show you were filthy but fine
But they shuttered your stores
When you opened the doors
To the cops who were bored once they'd run out of crime
Prettier, you're perfect, oh, please don't change a thing
Your mild billionaire mayor's now convinced he's a king
So the boring collect
I mean all disrespect
In the neighborhood bars I'd once dreamt I would drink
Prettier, I love you but you're freaking me out
There's a ton of the twist but we're fresh out of shout
Like a death in the hall
That you hear through your wall
Prettier, I love you but you're freaking me out
Prettier, I love you but you're bringing me down
Prettier, I love you but you're bringing me down
Like a death of the heart
Jesus, where do I start?
But you're still the one pool where I'd happily drown
And oh! Take me off your mailing list
For kids who think it still exists
Yes, for those who think it still exists
Maybe I'm wrong and maybe you're right
Maybe I'm wrong and maybe you're right
Maybe you're right, maybe I'm wrong
And just maybe you're right
And oh! Maybe mother told you true
And there'll always be somebody there for you
And you'll never be alone
But maybe she's wrong and maybe I'm right
And just maybe she's wrong
Maybe she's wrong and maybe I'm right
And if so, here's this song!
2017-10-20 02:50:24 +08:00
|
|
|
ReactNativeRenderer.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
2017-05-25 00:06:30 +08:00
|
|
|
{
|
2017-10-02 18:42:07 +08:00
|
|
|
// 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() {},
|
|
|
|
|
},
|
2017-05-25 00:06:30 +08:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:56:24 +08:00
|
|
|
injectInternals({
|
|
|
|
|
findFiberByHostInstance: ReactNativeComponentTree.getClosestInstanceFromNode,
|
|
|
|
|
findHostInstanceByFiber: ReactNativeFiberRenderer.findHostInstance,
|
2017-11-03 03:50:03 +08:00
|
|
|
getInspectorDataForViewTag: getInspectorDataForViewTag,
|
2017-08-03 01:56:24 +08:00
|
|
|
// This is an enum because we may add more (e.g. profiler build)
|
|
|
|
|
bundleType: __DEV__ ? 1 : 0,
|
|
|
|
|
version: ReactVersion,
|
2017-10-19 07:22:21 +08:00
|
|
|
rendererPackageName: 'react-native-renderer',
|
2017-08-03 01:56:24 +08:00
|
|
|
});
|
2017-02-07 01:36:59 +08:00
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
export default ReactNativeRenderer;
|