From 60b05133baafe9ec4020d5ddf99b71a2302ba3dc Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Thu, 19 Apr 2018 11:03:50 -0700 Subject: [PATCH] Unforked renderApplication() Summary: This allows toggling fabric renderer via the same renderApplication() Reviewed By: mdvacca Differential Revision: D7682524 fbshipit-source-id: 59be1d2bea15f5e13e64e2d72304d79f9cb7d084 --- Libraries/ReactNative/AppContainer.js | 4 +- Libraries/ReactNative/AppRegistry.js | 19 +------ Libraries/ReactNative/renderApplication.js | 8 ++- Libraries/ReactNative/renderFabricSurface.js | 59 -------------------- 4 files changed, 10 insertions(+), 80 deletions(-) delete mode 100644 Libraries/ReactNative/renderFabricSurface.js diff --git a/Libraries/ReactNative/AppContainer.js b/Libraries/ReactNative/AppContainer.js index 3060d6de450..cb1ea048e4a 100644 --- a/Libraries/ReactNative/AppContainer.js +++ b/Libraries/ReactNative/AppContainer.js @@ -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 { 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 = ; } diff --git a/Libraries/ReactNative/AppRegistry.js b/Libraries/ReactNative/AppRegistry.js index 8ddfb64118d..efe8e5584f2 100644 --- a/Libraries/ReactNative/AppRegistry.js +++ b/Libraries/ReactNative/AppRegistry.js @@ -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; type TaskProvider = () => Task; export type ComponentProvider = () => React$ComponentType; @@ -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); diff --git a/Libraries/ReactNative/renderApplication.js b/Libraries/ReactNative/renderApplication.js index 896c88207eb..8abfed26040 100644 --- a/Libraries/ReactNative/renderApplication.js +++ b/Libraries/ReactNative/renderApplication.js @@ -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( 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( renderable = {renderable}; } - ReactNative.render(renderable, rootTag); + if (fabric) { + ReactFabric.render(renderable, rootTag); + } else { + ReactNative.render(renderable, rootTag); + } } module.exports = renderApplication; diff --git a/Libraries/ReactNative/renderFabricSurface.js b/Libraries/ReactNative/renderFabricSurface.js deleted file mode 100644 index 0279f175992..00000000000 --- a/Libraries/ReactNative/renderFabricSurface.js +++ /dev/null @@ -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( - RootComponent: React.ComponentType, - initialProps: Props, - rootTag: any, - WrapperComponent?: ?React.ComponentType<*>, -) { - invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag); - - let renderable = ( - - - - ); - - // 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 = {renderable}; - } - - ReactFabric.render(renderable, rootTag); -} - -module.exports = renderFabricSurface;