From 370e0db970bb5cb3b58437d442d6889f21547b9b Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 8 Aug 2018 18:34:26 -0700 Subject: [PATCH] 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 --- Libraries/Components/View/View.js | 17 ++++++------- .../Components/View/ViewNativeComponent.js | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 Libraries/Components/View/ViewNativeComponent.js diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index 2cfa05a8c..35c0bfa4e 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -12,11 +12,10 @@ const React = require('React'); const TextAncestor = require('TextAncestor'); +const ViewNativeComponent = require('ViewNativeComponent'); const invariant = require('fbjs/lib/invariant'); -const requireNativeComponent = require('requireNativeComponent'); -import type {NativeComponent} from 'ReactNative'; import type {ViewProps} from 'ViewPropTypes'; export type Props = ViewProps; @@ -28,11 +27,13 @@ export type Props = ViewProps; * * @see http://facebook.github.io/react-native/docs/view.html */ -const RCTView = requireNativeComponent('RCTView'); -let ViewToExport = RCTView; +let ViewToExport = ViewNativeComponent; if (__DEV__) { - const View = (props: Props, forwardedRef: ?React.Ref<'RCTView'>) => { + const View = ( + props: Props, + forwardedRef: React.Ref, + ) => { return ( {hasTextAncestor => { @@ -40,7 +41,7 @@ if (__DEV__) { !hasTextAncestor, 'Nesting of within is not currently supported.', ); - return ; + return ; }} ); @@ -49,6 +50,4 @@ if (__DEV__) { ViewToExport = React.forwardRef(View); } -module.exports = ((ViewToExport: $FlowFixMe): Class< - NativeComponent, ->); +module.exports = ((ViewToExport: $FlowFixMe): typeof ViewNativeComponent); diff --git a/Libraries/Components/View/ViewNativeComponent.js b/Libraries/Components/View/ViewNativeComponent.js new file mode 100644 index 000000000..728e81beb --- /dev/null +++ b/Libraries/Components/View/ViewNativeComponent.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +const ReactNative = require('ReactNative'); + +const requireNativeComponent = require('requireNativeComponent'); + +import type {ViewProps} from 'ViewPropTypes'; + +type ViewNativeComponentType = Class>; + +const ViewNativeComponent = ((requireNativeComponent( + 'RCTView', +): any): ViewNativeComponentType); + +module.exports = ViewNativeComponent;