2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* @providesModule View
|
2015-04-03 18:03:41 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-11-04 12:40:26 +00:00
|
|
|
const NativeMethodsMixin = require('NativeMethodsMixin');
|
2016-12-19 14:26:07 +00:00
|
|
|
const Platform = require('Platform');
|
2017-04-12 23:09:48 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2017-05-23 14:55:52 +00:00
|
|
|
const React = require('React');
|
2016-01-27 17:04:14 +00:00
|
|
|
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
|
|
|
const ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
2017-03-23 16:08:46 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-07-07 21:24:25 +00:00
|
|
|
const createReactClass = require('create-react-class');
|
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
|
|
|
|
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
|
|
|
/**
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* The most fundamental component for building a UI.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/view.html
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2017-07-07 21:24:25 +00:00
|
|
|
const View = createReactClass({
|
|
|
|
displayName: 'View',
|
2016-06-23 09:18:10 +00:00
|
|
|
// TODO: We should probably expose the mixins, viewConfig, and statics publicly. For example,
|
|
|
|
// one of the props is of type AccessibilityComponentType. That is defined as a const[] above,
|
|
|
|
// but it is not rendered by the docs, since `statics` below is not rendered. So its Possible
|
|
|
|
// values had to be hardcoded.
|
2015-03-31 23:12:55 +00:00
|
|
|
mixins: [NativeMethodsMixin],
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-03-28 18:17:21 +00:00
|
|
|
// `propTypes` should not be accessed directly on View since this wrapper only
|
|
|
|
// exists for DEV mode. However it's important for them to be declared.
|
|
|
|
// If the object passed to `createClass` specifies `propTypes`, Flow will
|
2017-06-21 19:23:58 +00:00
|
|
|
// create a static type from it.
|
2017-03-28 18:17:21 +00:00
|
|
|
propTypes: ViewPropTypes,
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* `NativeMethodsMixin` will look for this when invoking `setNativeProps`. We
|
|
|
|
* make `this` look like an actual native component class.
|
|
|
|
*/
|
|
|
|
viewConfig: {
|
|
|
|
uiViewClassName: 'RCTView',
|
2015-05-08 16:45:43 +00:00
|
|
|
validAttributes: ReactNativeViewAttributes.RCTView
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2017-01-18 17:18:20 +00:00
|
|
|
contextTypes: {
|
2017-04-12 23:09:48 +00:00
|
|
|
isInAParentText: PropTypes.bool,
|
2017-01-18 17:18:20 +00:00
|
|
|
},
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
render: function() {
|
2017-01-18 17:18:20 +00:00
|
|
|
invariant(
|
|
|
|
!(this.context.isInAParentText && Platform.OS === 'android'),
|
|
|
|
'Nesting of <View> within <Text> is not supported on Android.');
|
|
|
|
|
2015-11-24 21:05:34 +00: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 23:12:55 +00:00
|
|
|
return <RCTView {...this.props} />;
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2016-01-27 17:04:14 +00:00
|
|
|
const RCTView = requireNativeComponent('RCTView', View, {
|
2015-11-20 08:47:24 +00:00
|
|
|
nativeOnly: {
|
|
|
|
nativeBackgroundAndroid: true,
|
2016-10-03 11:27:16 +00:00
|
|
|
nativeForegroundAndroid: true,
|
2015-11-20 08:47:24 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +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');
|
2016-01-27 17:04:14 +00:00
|
|
|
const viewConfig = UIManager.viewConfigs && UIManager.viewConfigs.RCTView || {};
|
|
|
|
for (const prop in viewConfig.nativeProps) {
|
|
|
|
const viewAny: any = View; // Appease flow
|
2015-05-08 16:45:43 +00:00
|
|
|
if (!viewAny.propTypes[prop] && !ReactNativeStyleAttributes[prop]) {
|
2015-04-22 04:07:17 +00:00
|
|
|
throw new Error(
|
|
|
|
'View is missing propType for native prop `' + prop + '`'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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__) {
|
2015-02-20 04:10:52 +00:00
|
|
|
ViewToExport = View;
|
|
|
|
}
|
|
|
|
|
2017-06-21 19:23:58 +00:00
|
|
|
// No one should depend on the DEV-mode createClass View wrapper.
|
|
|
|
module.exports = ((ViewToExport : any) : typeof RCTView);
|