2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2017-06-26 23:20:39 +00:00
|
|
|
* @format
|
2016-06-08 21:30:46 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-11-20 21:05:34 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-26 23:20:39 +00:00
|
|
|
const AppContainer = require('AppContainer');
|
|
|
|
const React = require('React');
|
2018-08-08 04:20:58 +00:00
|
|
|
const ReactFabricIndicator = require('ReactFabricIndicator');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-06-26 23:20:39 +00:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-03-07 05:41:51 +00:00
|
|
|
// require BackHandler so it sets the default handler that exits the app if no listeners respond
|
|
|
|
require('BackHandler');
|
2016-06-13 23:34:48 +00:00
|
|
|
|
2016-11-15 04:39:21 +00:00
|
|
|
function renderApplication<Props: Object>(
|
2017-08-18 01:36:54 +00:00
|
|
|
RootComponent: React.ComponentType<Props>,
|
2016-06-13 23:34:48 +00:00
|
|
|
initialProps: Props,
|
2017-06-26 23:20:39 +00:00
|
|
|
rootTag: any,
|
2017-08-18 01:36:54 +00:00
|
|
|
WrapperComponent?: ?React.ComponentType<*>,
|
2018-04-19 18:03:50 +00:00
|
|
|
fabric?: boolean,
|
2018-08-08 04:20:58 +00:00
|
|
|
showFabricIndicator?: boolean,
|
2015-03-24 18:30:58 +00:00
|
|
|
) {
|
2017-06-26 23:20:39 +00:00
|
|
|
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);
|
|
|
|
|
2017-11-17 21:30:06 +00:00
|
|
|
let renderable = (
|
2017-06-28 01:08:05 +00:00
|
|
|
<AppContainer rootTag={rootTag} WrapperComponent={WrapperComponent}>
|
2017-06-26 23:20:39 +00:00
|
|
|
<RootComponent {...initialProps} rootTag={rootTag} />
|
2018-08-08 04:20:58 +00:00
|
|
|
{fabric === true && showFabricIndicator === true ? (
|
|
|
|
<ReactFabricIndicator />
|
|
|
|
) : null}
|
2017-11-17 21:30:06 +00:00
|
|
|
</AppContainer>
|
2015-03-11 20:25:40 +00:00
|
|
|
);
|
2017-11-17 21:30:06 +00:00
|
|
|
|
|
|
|
// 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.
|
2017-11-20 21:39:48 +00:00
|
|
|
// For more info see https://fb.me/is-component-async
|
2017-11-17 21:30:06 +00:00
|
|
|
if (
|
2018-03-20 01:24:11 +00:00
|
|
|
/* $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. */
|
2017-11-17 21:30:06 +00:00
|
|
|
RootComponent.prototype != null &&
|
|
|
|
RootComponent.prototype.unstable_isAsyncReactComponent === true
|
|
|
|
) {
|
|
|
|
// $FlowFixMe This is not yet part of the official public API
|
2018-02-21 01:35:29 +00:00
|
|
|
const AsyncMode = React.unstable_AsyncMode;
|
|
|
|
renderable = <AsyncMode>{renderable}</AsyncMode>;
|
2017-11-17 21:30:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-19 18:03:50 +00:00
|
|
|
if (fabric) {
|
2018-05-12 00:09:14 +00:00
|
|
|
require('ReactFabric').render(renderable, rootTag);
|
2018-04-19 18:03:50 +00:00
|
|
|
} else {
|
2018-05-12 00:09:14 +00:00
|
|
|
require('ReactNative').render(renderable, rootTag);
|
2018-04-19 18:03:50 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = renderApplication;
|