Skip to content

Commit 94dac23

Browse files
fkgozalifacebook-github-bot
authored andcommitted
Added ReactFabric shim
Summary: A simple shim just like ReactNative.js Plus a fork of renderApplication that exclusively will call ReactFabric. Reviewed By: mdvacca Differential Revision: D6919080 fbshipit-source-id: 5807105a6c45dd99584eb92a5570c6076e2d56b9
1 parent 8a882fe commit 94dac23

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @providesModule ReactFabric
8+
* @flow
9+
*/
10+
'use strict';
11+
12+
// TODO @sema: Adjust types
13+
import type {ReactNativeType} from 'ReactNativeTypes';
14+
15+
let ReactFabric;
16+
17+
if (__DEV__) {
18+
ReactFabric = require('ReactFabric-dev');
19+
} else {
20+
ReactFabric = require('ReactFabric-prod');
21+
}
22+
23+
module.exports = (ReactFabric: ReactNativeType);

0 commit comments

Comments
 (0)