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
|
|
|
*
|
2018-01-15 03:32:26 +00:00
|
|
|
* @format
|
2018-05-09 07:47:48 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-05-09 07:47:46 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-12-19 14:26:07 +00:00
|
|
|
const Platform = require('Platform');
|
2017-05-23 14:55:52 +00:00
|
|
|
const React = require('React');
|
2016-01-27 17:04:14 +00:00
|
|
|
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
2018-05-09 07:47:46 +00:00
|
|
|
const TextAncestor = require('TextAncestor');
|
2017-03-23 16:08:46 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
2018-05-09 07:47:46 +00:00
|
|
|
|
2017-01-25 18:31:40 +00:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
2017-05-23 14:55:52 +00:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2016-02-15 23:13:42 +00:00
|
|
|
|
2018-05-09 07:47:48 +00:00
|
|
|
import type {NativeComponent} from 'ReactNative';
|
2017-05-23 14:55:52 +00:00
|
|
|
import type {ViewProps} from 'ViewPropTypes';
|
|
|
|
|
|
|
|
export type Props = ViewProps;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2018-03-10 02:26:58 +00:00
|
|
|
* The most fundamental component for building a UI, View is a container that
|
|
|
|
* supports layout with flexbox, style, some touch handling, and accessibility
|
|
|
|
* controls.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2018-03-10 02:26:58 +00:00
|
|
|
* @see http://facebook.github.io/react-native/docs/view.html
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-05-09 07:47:48 +00:00
|
|
|
const RCTView = requireNativeComponent(
|
|
|
|
'RCTView',
|
|
|
|
{
|
|
|
|
propTypes: ViewPropTypes,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nativeOnly: {
|
|
|
|
nativeBackgroundAndroid: true,
|
|
|
|
nativeForegroundAndroid: true,
|
|
|
|
},
|
2018-01-15 03:32:26 +00:00
|
|
|
},
|
2018-05-09 07:47:48 +00:00
|
|
|
);
|
2015-11-20 08:47:24 +00:00
|
|
|
|
2015-04-22 04:07:17 +00:00
|
|
|
if (__DEV__) {
|
2016-10-27 11:17:41 +00:00
|
|
|
const UIManager = require('UIManager');
|
2018-01-15 03:32:26 +00:00
|
|
|
const viewConfig =
|
|
|
|
(UIManager.viewConfigs && UIManager.viewConfigs.RCTView) || {};
|
2016-01-27 17:04:14 +00:00
|
|
|
for (const prop in viewConfig.nativeProps) {
|
2018-05-09 07:47:48 +00:00
|
|
|
if (!ViewPropTypes[prop] && !ReactNativeStyleAttributes[prop]) {
|
2015-04-22 04:07:17 +00:00
|
|
|
throw new Error(
|
2018-01-15 03:32:26 +00:00
|
|
|
'View is missing propType for native prop `' + prop + '`',
|
2015-04-22 04:07:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-01-27 17:04:14 +00:00
|
|
|
let ViewToExport = RCTView;
|
2017-06-21 19:23:58 +00:00
|
|
|
if (__DEV__) {
|
2018-05-09 07:47:48 +00:00
|
|
|
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
|
|
|
|
ViewToExport = React.forwardRef((props, ref) => (
|
|
|
|
<TextAncestor.Consumer>
|
|
|
|
{hasTextAncestor => {
|
|
|
|
// TODO: Change iOS to behave the same as Android.
|
|
|
|
invariant(
|
|
|
|
!hasTextAncestor || Platform.OS !== 'android',
|
|
|
|
'Nesting of <View> within <Text> is not supported on Android.',
|
|
|
|
);
|
|
|
|
return <RCTView {...props} ref={ref} />;
|
|
|
|
}}
|
|
|
|
</TextAncestor.Consumer>
|
|
|
|
));
|
|
|
|
ViewToExport.displayName = 'View';
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 07:47:48 +00:00
|
|
|
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps, any>>);
|