From ebb8c675658945c104bf4697a4976a615375dfbd Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 13 May 2015 17:39:22 +0800 Subject: [PATCH 1/4] fix exception when ES6 class with no propTypes defined before calling requireNativeComponent --- Libraries/ReactIOS/verifyPropTypes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/ReactIOS/verifyPropTypes.js b/Libraries/ReactIOS/verifyPropTypes.js index ab1d61728895fd..d5484de47408b2 100644 --- a/Libraries/ReactIOS/verifyPropTypes.js +++ b/Libraries/ReactIOS/verifyPropTypes.js @@ -24,7 +24,8 @@ function verifyPropTypes( } var nativeProps = viewConfig.nativeProps; for (var prop in nativeProps) { - if (!component.propTypes[prop] && + if (component.propTypes != undefined && + !component.propTypes[prop] && !View.propTypes[prop] && !ReactIOSStyleAttributes[prop] && (!nativePropsToIgnore || !nativePropsToIgnore[prop])) { From ee6ac64ebf94a9dca818e9c76e126f8e5ff3357b Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 14 May 2015 10:45:59 +0800 Subject: [PATCH 2/4] fix code style #1260 --- Libraries/ReactIOS/verifyPropTypes.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Libraries/ReactIOS/verifyPropTypes.js b/Libraries/ReactIOS/verifyPropTypes.js index d5484de47408b2..c1231acd62eb14 100644 --- a/Libraries/ReactIOS/verifyPropTypes.js +++ b/Libraries/ReactIOS/verifyPropTypes.js @@ -24,8 +24,7 @@ function verifyPropTypes( } var nativeProps = viewConfig.nativeProps; for (var prop in nativeProps) { - if (component.propTypes != undefined && - !component.propTypes[prop] && + if ((component.propTypes && !component.propTypes[prop]) && !View.propTypes[prop] && !ReactIOSStyleAttributes[prop] && (!nativePropsToIgnore || !nativePropsToIgnore[prop])) { From 62fcfec203a6883f8f89774b01916c1c6be1c410 Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 14 May 2015 20:33:59 +0800 Subject: [PATCH 3/4] Throw a helpful error message when component.propTypes is not defined #1260 --- Libraries/ReactIOS/verifyPropTypes.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Libraries/ReactIOS/verifyPropTypes.js b/Libraries/ReactIOS/verifyPropTypes.js index c1231acd62eb14..cf9edb41b3ee6c 100644 --- a/Libraries/ReactIOS/verifyPropTypes.js +++ b/Libraries/ReactIOS/verifyPropTypes.js @@ -22,9 +22,16 @@ function verifyPropTypes( if (!viewConfig) { return; // This happens for UnimplementedView. } + + if (!component.propTypes) { + throw new Error( + '`' + component.name + '` has no propTypes defined`' + ); + }; + var nativeProps = viewConfig.nativeProps; for (var prop in nativeProps) { - if ((component.propTypes && !component.propTypes[prop]) && + if (!component.propTypes[prop] && !View.propTypes[prop] && !ReactIOSStyleAttributes[prop] && (!nativePropsToIgnore || !nativePropsToIgnore[prop])) { From 26184349f15a77e6d9ae02a15574a9b0d2af8f14 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 16 May 2015 09:30:04 +0800 Subject: [PATCH 4/4] Check the name and displayName of component #1260 ES6 classes name works, but for React.createClass displayName works. --- Libraries/ReactIOS/verifyPropTypes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/ReactIOS/verifyPropTypes.js b/Libraries/ReactIOS/verifyPropTypes.js index cf9edb41b3ee6c..fb453a14c30395 100644 --- a/Libraries/ReactIOS/verifyPropTypes.js +++ b/Libraries/ReactIOS/verifyPropTypes.js @@ -25,7 +25,7 @@ function verifyPropTypes( if (!component.propTypes) { throw new Error( - '`' + component.name + '` has no propTypes defined`' + '`' + (component.name || component.displayName) + '` has no propTypes defined`' ); }; @@ -36,7 +36,7 @@ function verifyPropTypes( !ReactIOSStyleAttributes[prop] && (!nativePropsToIgnore || !nativePropsToIgnore[prop])) { throw new Error( - '`' + component.displayName + '` has no propType for native prop `' + + '`' + (component.name || component.displayName) + '` has no propType for native prop `' + viewConfig.uiViewClassName + '.' + prop + '` of native type `' + nativeProps[prop].type + '`' );