2015-04-16 18:17:19 -07: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.
|
|
|
|
*
|
|
|
|
* @providesModule verifyPropTypes
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-05-08 09:45:43 -07:00
|
|
|
var ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
2015-04-16 18:17:19 -07:00
|
|
|
|
2017-08-17 18:36:54 -07:00
|
|
|
export type ComponentInterface = React$ComponentType<any> | {
|
2016-08-09 06:32:41 -07:00
|
|
|
name?: string,
|
|
|
|
displayName?: string,
|
|
|
|
propTypes: Object,
|
2015-07-24 18:31:55 -07:00
|
|
|
};
|
|
|
|
|
2015-04-16 18:17:19 -07:00
|
|
|
function verifyPropTypes(
|
2015-07-24 18:31:55 -07:00
|
|
|
componentInterface: ComponentInterface,
|
2015-04-16 18:17:19 -07:00
|
|
|
viewConfig: Object,
|
2015-07-24 18:31:55 -07:00
|
|
|
nativePropsToIgnore?: ?Object
|
2015-04-16 18:17:19 -07:00
|
|
|
) {
|
|
|
|
if (!viewConfig) {
|
|
|
|
return; // This happens for UnimplementedView.
|
|
|
|
}
|
2016-06-23 08:27:29 -07:00
|
|
|
var componentName =
|
2015-07-24 18:31:55 -07:00
|
|
|
componentInterface.displayName ||
|
2016-06-23 08:27:29 -07:00
|
|
|
componentInterface.name ||
|
2015-07-24 18:31:55 -07:00
|
|
|
'unknown';
|
2016-06-23 08:27:29 -07:00
|
|
|
|
2017-03-28 11:17:21 -07:00
|
|
|
// ReactNative `View.propTypes` have been deprecated in favor of
|
|
|
|
// `ViewPropTypes`. In their place a temporary getter has been added with a
|
|
|
|
// deprecated warning message. Avoid triggering that warning here by using
|
|
|
|
// temporary workaround, __propTypesSecretDontUseThesePlease.
|
|
|
|
// TODO (bvaughn) Revert this particular change any time after April 1
|
|
|
|
var propTypes =
|
|
|
|
(componentInterface : any).__propTypesSecretDontUseThesePlease ||
|
|
|
|
componentInterface.propTypes;
|
|
|
|
|
|
|
|
if (!propTypes) {
|
2015-05-18 11:53:23 -07:00
|
|
|
throw new Error(
|
2017-08-29 14:54:33 -07:00
|
|
|
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
|
|
|
|
* comment suppresses an error when upgrading Flow's support for React.
|
|
|
|
* To see the error delete this comment and run Flow. */
|
2015-05-18 11:53:23 -07:00
|
|
|
'`' + componentName + '` has no propTypes defined`'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-26 19:25:11 -07:00
|
|
|
var nativeProps = viewConfig.NativeProps;
|
2015-04-21 21:07:17 -07:00
|
|
|
for (var prop in nativeProps) {
|
2017-03-28 11:17:21 -07:00
|
|
|
if (!propTypes[prop] &&
|
2015-05-08 09:45:43 -07:00
|
|
|
!ReactNativeStyleAttributes[prop] &&
|
2015-04-16 18:17:19 -07:00
|
|
|
(!nativePropsToIgnore || !nativePropsToIgnore[prop])) {
|
2015-12-09 04:04:23 -08:00
|
|
|
var message;
|
2017-03-28 11:17:21 -07:00
|
|
|
if (propTypes.hasOwnProperty(prop)) {
|
2017-08-29 14:54:33 -07:00
|
|
|
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
|
|
|
|
* comment suppresses an error when upgrading Flow's support for React.
|
|
|
|
* To see the error delete this comment and run Flow. */
|
2015-12-09 04:04:23 -08:00
|
|
|
message = '`' + componentName + '` has incorrectly defined propType for native prop `' +
|
|
|
|
viewConfig.uiViewClassName + '.' + prop + '` of native type `' + nativeProps[prop];
|
|
|
|
} else {
|
2017-08-29 14:54:33 -07:00
|
|
|
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
|
|
|
|
* comment suppresses an error when upgrading Flow's support for React.
|
|
|
|
* To see the error delete this comment and run Flow. */
|
2015-12-09 04:04:23 -08:00
|
|
|
message = '`' + componentName + '` has no propType for native prop `' +
|
2015-04-16 18:17:19 -07:00
|
|
|
viewConfig.uiViewClassName + '.' + prop + '` of native type `' +
|
2015-12-09 04:04:23 -08:00
|
|
|
nativeProps[prop] + '`';
|
2016-06-01 08:44:03 -07:00
|
|
|
}
|
2016-01-28 20:13:32 -08:00
|
|
|
message += '\nIf you haven\'t changed this prop yourself, this usually means that ' +
|
|
|
|
'your versions of the native code and JavaScript code are out of sync. Updating both ' +
|
|
|
|
'should make this error go away.';
|
2015-12-09 04:04:23 -08:00
|
|
|
throw new Error(message);
|
2015-04-16 18:17:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = verifyPropTypes;
|