Skip to content

Commit 370e0db

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Move View native require call to new file
Summary: Moving out the requireNativeComponent call into a new file. We want this long term for all of our view managers to support codegen of the native side and so we can move the viewConfigs into JS. Reviewed By: yungsters Differential Revision: D9231619 fbshipit-source-id: 7c89587cc6a76e92b309c4941577291e56af8c7c
1 parent 6104123 commit 370e0db

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

Libraries/Components/View/View.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
const React = require('React');
1414
const TextAncestor = require('TextAncestor');
15+
const ViewNativeComponent = require('ViewNativeComponent');
1516

1617
const invariant = require('fbjs/lib/invariant');
17-
const requireNativeComponent = require('requireNativeComponent');
1818

19-
import type {NativeComponent} from 'ReactNative';
2019
import type {ViewProps} from 'ViewPropTypes';
2120

2221
export type Props = ViewProps;
@@ -28,19 +27,21 @@ export type Props = ViewProps;
2827
*
2928
* @see http://facebook.github.io/react-native/docs/view.html
3029
*/
31-
const RCTView = requireNativeComponent('RCTView');
3230

33-
let ViewToExport = RCTView;
31+
let ViewToExport = ViewNativeComponent;
3432
if (__DEV__) {
35-
const View = (props: Props, forwardedRef: ?React.Ref<'RCTView'>) => {
33+
const View = (
34+
props: Props,
35+
forwardedRef: React.Ref<typeof ViewNativeComponent>,
36+
) => {
3637
return (
3738
<TextAncestor.Consumer>
3839
{hasTextAncestor => {
3940
invariant(
4041
!hasTextAncestor,
4142
'Nesting of <View> within <Text> is not currently supported.',
4243
);
43-
return <RCTView {...props} ref={forwardedRef} />;
44+
return <ViewNativeComponent {...props} ref={forwardedRef} />;
4445
}}
4546
</TextAncestor.Consumer>
4647
);
@@ -49,6 +50,4 @@ if (__DEV__) {
4950
ViewToExport = React.forwardRef(View);
5051
}
5152

52-
module.exports = ((ViewToExport: $FlowFixMe): Class<
53-
NativeComponent<ViewProps>,
54-
>);
53+
module.exports = ((ViewToExport: $FlowFixMe): typeof ViewNativeComponent);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
const ReactNative = require('ReactNative');
14+
15+
const requireNativeComponent = require('requireNativeComponent');
16+
17+
import type {ViewProps} from 'ViewPropTypes';
18+
19+
type ViewNativeComponentType = Class<ReactNative.NativeComponent<ViewProps>>;
20+
21+
const ViewNativeComponent = ((requireNativeComponent(
22+
'RCTView',
23+
): any): ViewNativeComponentType);
24+
25+
module.exports = ViewNativeComponent;

0 commit comments

Comments
 (0)