Unforked renderApplication()

Summary: This allows toggling fabric renderer via the same renderApplication()

Reviewed By: mdvacca

Differential Revision: D7682524

fbshipit-source-id: 59be1d2bea15f5e13e64e2d72304d79f9cb7d084
This commit is contained in:
Kevin Gozali
2018-04-19 11:03:50 -07:00
committed by Facebook Github Bot
parent dc836780cb
commit 60b05133ba
4 changed files with 10 additions and 80 deletions

View File

@@ -27,7 +27,6 @@ type Props = {|
* suppresses an error when upgrading Flow's support for React. To see the
* error delete this comment and run Flow. */
children?: React.Children,
fabric?: boolean,
rootTag: number,
WrapperComponent?: ?React.ComponentType<*>,
|};
@@ -91,8 +90,7 @@ class AppContainer extends React.Component<Props, State> {
render(): React.Node {
let yellowBox = null;
if (__DEV__) {
if (!global.__RCTProfileIsProfiling && !this.props.fabric) {
// TODO: Fabric doesn't support YellowBox.
if (!global.__RCTProfileIsProfiling) {
const YellowBox = require('YellowBox');
yellowBox = <YellowBox />;
}

View File

@@ -20,10 +20,6 @@ const infoLog = require('infoLog');
const invariant = require('fbjs/lib/invariant');
const renderApplication = require('renderApplication');
// Renderer provider must be supplied by each app. If none, traditional
// renderApplication() will be used.
let fabricRendererProvider: ?() => typeof renderApplication = null;
type Task = (taskData: any) => Promise<void>;
type TaskProvider = () => Task;
export type ComponentProvider = () => React$ComponentType<any>;
@@ -102,19 +98,12 @@ const AppRegistry = {
runnables[appKey] = {
componentProvider,
run: appParameters => {
let renderFunc = renderApplication;
if (appParameters.fabric) {
invariant(
fabricRendererProvider != null,
'A Fabric renderer provider must be set to render Fabric components',
);
renderFunc = fabricRendererProvider();
}
renderFunc(
renderApplication(
componentProviderInstrumentationHook(componentProvider),
appParameters.initialProps,
appParameters.rootTag,
wrapperComponentProvider && wrapperComponentProvider(appParameters),
appParameters.fabric,
);
},
};
@@ -249,10 +238,6 @@ const AppRegistry = {
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId);
});
},
setFabricRendererProvider(provider: () => typeof renderApplication): void {
fabricRendererProvider = provider;
},
};
BatchedBridge.registerCallableModule('AppRegistry', AppRegistry);

View File

@@ -13,6 +13,7 @@
const AppContainer = require('AppContainer');
const React = require('React');
const ReactFabric = require('ReactFabric');
const ReactNative = require('ReactNative');
const invariant = require('fbjs/lib/invariant');
@@ -25,6 +26,7 @@ function renderApplication<Props: Object>(
initialProps: Props,
rootTag: any,
WrapperComponent?: ?React.ComponentType<*>,
fabric?: boolean,
) {
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);
@@ -49,7 +51,11 @@ function renderApplication<Props: Object>(
renderable = <AsyncMode>{renderable}</AsyncMode>;
}
ReactNative.render(renderable, rootTag);
if (fabric) {
ReactFabric.render(renderable, rootTag);
} else {
ReactNative.render(renderable, rootTag);
}
}
module.exports = renderApplication;

View File

@@ -1,59 +0,0 @@
/**
* Copyright (c) 2015-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.
*
* @providesModule renderFabricSurface
* @format
* @flow
*/
'use strict';
const AppContainer = require('AppContainer');
const React = require('React');
const ReactFabric = require('ReactFabric');
const invariant = require('fbjs/lib/invariant');
// require BackHandler so it sets the default handler that exits the app if no listeners respond
require('BackHandler');
// Note: this is a fork of renderApplication.js to simply invoke ReactFabric.
function renderFabricSurface<Props: Object>(
RootComponent: React.ComponentType<Props>,
initialProps: Props,
rootTag: any,
WrapperComponent?: ?React.ComponentType<*>,
) {
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);
let renderable = (
<AppContainer
fabric={true}
rootTag={rootTag}
WrapperComponent={WrapperComponent}>
<RootComponent {...initialProps} rootTag={rootTag} />
</AppContainer>
);
// If the root component is async, the user probably wants the initial render
// to be async also. To do this, wrap AppContainer with an async marker.
// For more info see https://fb.me/is-component-async
if (
/* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.68 was deployed. To see the error delete this
* comment and run Flow. */
RootComponent.prototype != null &&
RootComponent.prototype.unstable_isAsyncReactComponent === true
) {
// $FlowFixMe This is not yet part of the official public API
const AsyncMode = React.unstable_AsyncMode;
renderable = <AsyncMode>{renderable}</AsyncMode>;
}
ReactFabric.render(renderable, rootTag);
}
module.exports = renderFabricSurface;