Skip to content

Commit

Permalink
hook up offscreen api to runApplication
Browse files Browse the repository at this point in the history
Summary:
[Changelog]: Internal

integrate the offscreen component when we render an application that is configured to do so

Reviewed By: rubennorte

Differential Revision: D39458472

fbshipit-source-id: 9bd492ca258723cb9cf0b7e4f6c9b0005554e91e
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 8, 2022
1 parent c48cb04 commit 0d3596a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Libraries/ReactNative/renderApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/

import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
import type {DisplayModeType} from './DisplayMode';

import GlobalPerformanceLogger from '../Utilities/GlobalPerformanceLogger';
import PerformanceLoggerContext from '../Utilities/PerformanceLoggerContext';
import AppContainer from './AppContainer';
import DisplayMode, {type DisplayModeType} from './DisplayMode';
import getCachedComponentWithDebugName from './getCachedComponentWithDebugName';
import * as Renderer from './RendererProxy';
import invariant from 'invariant';
Expand All @@ -22,6 +22,11 @@ import * as React from 'react';
// require BackHandler so it sets the default handler that exits the app if no listeners respond
import '../Utilities/BackHandler';

type OffscreenType = React.AbstractComponent<{
mode: 'visible' | 'hidden',
children: React.Node,
}>;

export default function renderApplication<Props: Object>(
RootComponent: React.ComponentType<Props>,
initialProps: Props,
Expand All @@ -34,6 +39,7 @@ export default function renderApplication<Props: Object>(
debugName?: string,
displayMode?: ?DisplayModeType,
useConcurrentRoot?: boolean,
useOffscreen?: boolean,
) {
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);

Expand Down Expand Up @@ -64,6 +70,19 @@ export default function renderApplication<Props: Object>(
);
}

if (useOffscreen && displayMode != null) {
// $FlowFixMe[incompatible-type]
// $FlowFixMe[prop-missing]
const Offscreen: OffscreenType = React.unstable_Offscreen;

renderable = (
<Offscreen
mode={displayMode === DisplayMode.VISIBLE ? 'visible' : 'hidden'}>
{renderable}
</Offscreen>
);
}

performanceLogger.startTimespan('renderApplication_React_render');
performanceLogger.setExtra(
'usedReactConcurrentRoot',
Expand Down

0 comments on commit 0d3596a

Please sign in to comment.