2015-04-17 01:17:19 +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-04-17 01:17:19 +00:00
|
|
|
*
|
|
|
|
* @providesModule verifyPropTypes
|
|
|
|
* @flow
|
2017-09-25 05:57:35 +00:00
|
|
|
* @format
|
2015-04-17 01:17:19 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-05-08 16:45:43 +00:00
|
|
|
var ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
2015-04-17 01:17:19 +00:00
|
|
|
|
2017-09-25 05:57:35 +00:00
|
|
|
export type ComponentInterface =
|
|
|
|
| React$ComponentType<any>
|
|
|
|
| {
|
|
|
|
name?: string,
|
|
|
|
displayName?: string,
|
|
|
|
propTypes: Object,
|
|
|
|
};
|
2015-07-25 01:31:55 +00:00
|
|
|
|
2015-04-17 01:17:19 +00:00
|
|
|
function verifyPropTypes(
|
2015-07-25 01:31:55 +00:00
|
|
|
componentInterface: ComponentInterface,
|
2015-04-17 01:17:19 +00:00
|
|
|
viewConfig: Object,
|
2017-09-25 05:57:35 +00:00
|
|
|
nativePropsToIgnore?: ?Object,
|
2015-04-17 01:17:19 +00:00
|
|
|
) {
|
|
|
|
if (!viewConfig) {
|
|
|
|
return; // This happens for UnimplementedView.
|
|
|
|
}
|
2016-06-23 15:27:29 +00:00
|
|
|
var componentName =
|
2017-09-25 05:57:35 +00:00
|
|
|
componentInterface.displayName || componentInterface.name || 'unknown';
|
2016-06-23 15:27:29 +00:00
|
|
|
|
2017-03-28 18:17:21 +00: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 =
|
2017-09-25 05:57:35 +00:00
|
|
|
(componentInterface: any).__propTypesSecretDontUseThesePlease ||
|
2017-03-28 18:17:21 +00:00
|
|
|
componentInterface.propTypes;
|
|
|
|
|
|
|
|
if (!propTypes) {
|
2017-09-25 05:57:35 +00:00
|
|
|
throw new Error('`' + componentName + '` has no propTypes defined`');
|
2015-05-18 18:53:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 02:25:11 +00:00
|
|
|
var nativeProps = viewConfig.NativeProps;
|
2015-04-22 04:07:17 +00:00
|
|
|
for (var prop in nativeProps) {
|
2017-09-25 05:57:35 +00:00
|
|
|
if (
|
|
|
|
!propTypes[prop] &&
|
|
|
|
!ReactNativeStyleAttributes[prop] &&
|
|
|
|
(!nativePropsToIgnore || !nativePropsToIgnore[prop])
|
|
|
|
) {
|
2015-12-09 12:04:23 +00:00
|
|
|
var message;
|
2017-03-28 18:17:21 +00:00
|
|
|
if (propTypes.hasOwnProperty(prop)) {
|
2017-09-25 05:57:35 +00:00
|
|
|
message =
|
|
|
|
'`' +
|
|
|
|
componentName +
|
|
|
|
'` has incorrectly defined propType for native prop `' +
|
|
|
|
viewConfig.uiViewClassName +
|
|
|
|
'.' +
|
|
|
|
prop +
|
|
|
|
'` of native type `' +
|
|
|
|
nativeProps[prop];
|
2015-12-09 12:04:23 +00:00
|
|
|
} else {
|
2017-09-25 05:57:35 +00:00
|
|
|
message =
|
|
|
|
'`' +
|
|
|
|
componentName +
|
|
|
|
'` has no propType for native prop `' +
|
|
|
|
viewConfig.uiViewClassName +
|
|
|
|
'.' +
|
|
|
|
prop +
|
|
|
|
'` of native type `' +
|
|
|
|
nativeProps[prop] +
|
|
|
|
'`';
|
2016-06-01 15:44:03 +00:00
|
|
|
}
|
2017-09-25 05:57:35 +00:00
|
|
|
message +=
|
|
|
|
"\nIf you haven't changed this prop yourself, this usually means that " +
|
2016-01-29 04:13:32 +00:00
|
|
|
'your versions of the native code and JavaScript code are out of sync. Updating both ' +
|
|
|
|
'should make this error go away.';
|
2015-12-09 12:04:23 +00:00
|
|
|
throw new Error(message);
|
2015-04-17 01:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = verifyPropTypes;
|