2015-04-16 18:17:19 -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-04-16 18:17:19 -07:00
|
|
|
*
|
|
|
|
* @providesModule verifyPropTypes
|
|
|
|
* @flow
|
2017-09-24 22:57:35 -07:00
|
|
|
* @format
|
2015-04-16 18:17:19 -07:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-05-08 09:45:43 -07:00
|
|
|
var ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
2015-04-16 18:17:19 -07:00
|
|
|
|
2017-09-24 22:57:35 -07:00
|
|
|
export type ComponentInterface =
|
|
|
|
| React$ComponentType<any>
|
|
|
|
| {
|
|
|
|
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,
|
2017-09-24 22:57:35 -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 =
|
2017-09-24 22:57:35 -07:00
|
|
|
componentInterface.displayName || componentInterface.name || '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 =
|
2017-09-24 22:57:35 -07:00
|
|
|
(componentInterface: any).__propTypesSecretDontUseThesePlease ||
|
2017-03-28 11:17:21 -07:00
|
|
|
componentInterface.propTypes;
|
|
|
|
|
|
|
|
if (!propTypes) {
|
2017-09-24 22:57:35 -07:00
|
|
|
throw new Error('`' + componentName + '` has no propTypes defined`');
|
2015-05-18 11:53:23 -07:00
|
|
|
}
|
|
|
|
|
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-09-24 22:57:35 -07:00
|
|
|
if (
|
|
|
|
!propTypes[prop] &&
|
|
|
|
!ReactNativeStyleAttributes[prop] &&
|
|
|
|
(!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-09-24 22:57:35 -07:00
|
|
|
message =
|
|
|
|
'`' +
|
|
|
|
componentName +
|
|
|
|
'` has incorrectly defined propType for native prop `' +
|
|
|
|
viewConfig.uiViewClassName +
|
|
|
|
'.' +
|
|
|
|
prop +
|
|
|
|
'` of native type `' +
|
|
|
|
nativeProps[prop];
|
2015-12-09 04:04:23 -08:00
|
|
|
} else {
|
2017-09-24 22:57:35 -07:00
|
|
|
message =
|
|
|
|
'`' +
|
|
|
|
componentName +
|
|
|
|
'` has no propType for native prop `' +
|
|
|
|
viewConfig.uiViewClassName +
|
|
|
|
'.' +
|
|
|
|
prop +
|
|
|
|
'` of native type `' +
|
|
|
|
nativeProps[prop] +
|
|
|
|
'`';
|
2016-06-01 08:44:03 -07:00
|
|
|
}
|
2017-09-24 22:57:35 -07:00
|
|
|
message +=
|
|
|
|
"\nIf you haven't changed this prop yourself, this usually means that " +
|
2016-01-28 20:13:32 -08: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 04:04:23 -08:00
|
|
|
throw new Error(message);
|
2015-04-16 18:17:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = verifyPropTypes;
|