2015-02-19 20:10:52 -08:00
|
|
|
/**
|
2015-03-23 13:35:08 -07:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-16 18:24:55 -08: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-19 20:10:52 -08:00
|
|
|
*
|
2015-04-03 11:03:41 -07:00
|
|
|
* @flow
|
2018-01-14 19:32:26 -08:00
|
|
|
* @format
|
2015-02-19 20:10:52 -08:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-12-19 06:26:07 -08:00
|
|
|
const Platform = require('Platform');
|
2017-05-23 07:55:52 -07:00
|
|
|
const React = require('React');
|
2018-03-09 18:26:58 -08:00
|
|
|
const ReactNative = require('ReactNative');
|
2016-01-27 09:04:14 -08:00
|
|
|
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
|
|
|
const ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
2017-03-23 09:08:46 -07:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
2018-01-14 19:32:33 -08:00
|
|
|
const {ViewContextTypes} = require('ViewContext');
|
2017-01-25 10:31:40 -08:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
2017-05-23 07:55:52 -07:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2016-02-15 15:13:42 -08:00
|
|
|
|
2017-05-23 07:55:52 -07:00
|
|
|
import type {ViewProps} from 'ViewPropTypes';
|
2018-01-14 19:32:33 -08:00
|
|
|
import type {ViewChildContext} from 'ViewContext';
|
2017-05-23 07:55:52 -07:00
|
|
|
|
|
|
|
export type Props = ViewProps;
|
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
/**
|
2018-03-09 18:26:58 -08: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-19 20:10:52 -08:00
|
|
|
*
|
2018-03-09 18:26:58 -08:00
|
|
|
* @see http://facebook.github.io/react-native/docs/view.html
|
2015-02-19 20:10:52 -08:00
|
|
|
*/
|
2018-03-09 18:26:58 -08:00
|
|
|
class View extends ReactNative.NativeComponent<Props> {
|
|
|
|
static propTypes = ViewPropTypes;
|
|
|
|
static childContextTypes = ViewContextTypes;
|
2017-03-28 11:17:21 -07:00
|
|
|
|
2018-03-09 18:26:58 -08:00
|
|
|
viewConfig = {
|
2015-02-19 20:10:52 -08:00
|
|
|
uiViewClassName: 'RCTView',
|
2018-01-14 19:32:26 -08:00
|
|
|
validAttributes: ReactNativeViewAttributes.RCTView,
|
2018-03-09 18:26:58 -08:00
|
|
|
};
|
2018-01-14 19:32:33 -08:00
|
|
|
|
|
|
|
getChildContext(): ViewChildContext {
|
|
|
|
return {
|
|
|
|
isInAParentText: false,
|
|
|
|
};
|
2018-03-09 18:26:58 -08:00
|
|
|
}
|
2017-01-18 09:18:20 -08:00
|
|
|
|
2018-01-14 19:32:26 -08:00
|
|
|
render() {
|
2017-01-18 09:18:20 -08:00
|
|
|
invariant(
|
|
|
|
!(this.context.isInAParentText && Platform.OS === 'android'),
|
2018-01-14 19:32:26 -08:00
|
|
|
'Nesting of <View> within <Text> is not supported on Android.',
|
|
|
|
);
|
2017-01-18 09:18:20 -08:00
|
|
|
|
2015-11-24 13:05:34 -08:00
|
|
|
// WARNING: This method will not be used in production mode as in that mode we
|
|
|
|
// replace wrapper component View with generated native wrapper RCTView. Avoid
|
|
|
|
// adding functionality this component that you'd want to be available in both
|
|
|
|
// dev and prod modes.
|
2015-03-31 16:12:55 -07:00
|
|
|
return <RCTView {...this.props} />;
|
2018-03-09 18:26:58 -08:00
|
|
|
}
|
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2016-01-27 09:04:14 -08:00
|
|
|
const RCTView = requireNativeComponent('RCTView', View, {
|
2015-11-20 00:47:24 -08:00
|
|
|
nativeOnly: {
|
|
|
|
nativeBackgroundAndroid: true,
|
2016-10-03 04:27:16 -07:00
|
|
|
nativeForegroundAndroid: true,
|
2018-01-14 19:32:26 -08:00
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
});
|
2015-11-20 00:47:24 -08:00
|
|
|
|
2015-04-21 21:07:17 -07:00
|
|
|
if (__DEV__) {
|
2016-10-27 04:17:41 -07:00
|
|
|
const UIManager = require('UIManager');
|
2018-01-14 19:32:26 -08:00
|
|
|
const viewConfig =
|
|
|
|
(UIManager.viewConfigs && UIManager.viewConfigs.RCTView) || {};
|
2016-01-27 09:04:14 -08:00
|
|
|
for (const prop in viewConfig.nativeProps) {
|
|
|
|
const viewAny: any = View; // Appease flow
|
2015-05-08 09:45:43 -07:00
|
|
|
if (!viewAny.propTypes[prop] && !ReactNativeStyleAttributes[prop]) {
|
2015-04-21 21:07:17 -07:00
|
|
|
throw new Error(
|
2018-01-14 19:32:26 -08:00
|
|
|
'View is missing propType for native prop `' + prop + '`',
|
2015-04-21 21:07:17 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2016-01-27 09:04:14 -08:00
|
|
|
let ViewToExport = RCTView;
|
2017-06-21 12:23:58 -07:00
|
|
|
if (__DEV__) {
|
2015-02-19 20:10:52 -08:00
|
|
|
ViewToExport = View;
|
|
|
|
}
|
|
|
|
|
2017-06-21 12:23:58 -07:00
|
|
|
// No one should depend on the DEV-mode createClass View wrapper.
|
2018-03-09 14:55:04 -08:00
|
|
|
module.exports = ((ViewToExport: any): typeof View);
|