|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + * |
| 9 | + * @providesModule renderFabricSurface |
| 10 | + * @format |
| 11 | + * @flow |
| 12 | + */ |
| 13 | + |
| 14 | +'use strict'; |
| 15 | + |
| 16 | +const AppContainer = require('AppContainer'); |
| 17 | +const React = require('React'); |
| 18 | +const ReactFabric = require('ReactFabric'); |
| 19 | + |
| 20 | +const invariant = require('fbjs/lib/invariant'); |
| 21 | + |
| 22 | +// require BackHandler so it sets the default handler that exits the app if no listeners respond |
| 23 | +require('BackHandler'); |
| 24 | + |
| 25 | +// Note: this is a fork of renderApplication.js to simply invoke ReactFabric. |
| 26 | +function renderFabricSurface<Props: Object>( |
| 27 | + RootComponent: React.ComponentType<Props>, |
| 28 | + initialProps: Props, |
| 29 | + rootTag: any, |
| 30 | + WrapperComponent?: ?React.ComponentType<*>, |
| 31 | +) { |
| 32 | + invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag); |
| 33 | + |
| 34 | + let renderable = ( |
| 35 | + <AppContainer rootTag={rootTag} WrapperComponent={WrapperComponent}> |
| 36 | + <RootComponent {...initialProps} rootTag={rootTag} /> |
| 37 | + </AppContainer> |
| 38 | + ); |
| 39 | + |
| 40 | + // If the root component is async, the user probably wants the initial render |
| 41 | + // to be async also. To do this, wrap AppContainer with an async marker. |
| 42 | + // For more info see https://fb.me/is-component-async |
| 43 | + if ( |
| 44 | + RootComponent.prototype != null && |
| 45 | + RootComponent.prototype.unstable_isAsyncReactComponent === true |
| 46 | + ) { |
| 47 | + // $FlowFixMe This is not yet part of the official public API |
| 48 | + class AppContainerAsyncWrapper extends React.unstable_AsyncComponent { |
| 49 | + render() { |
| 50 | + return this.props.children; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + renderable = ( |
| 55 | + <AppContainerAsyncWrapper>{renderable}</AppContainerAsyncWrapper> |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + ReactFabric.render(renderable, rootTag); |
| 60 | +} |
| 61 | + |
| 62 | +module.exports = renderFabricSurface; |
0 commit comments