From 963e6e9d36bb8f88caaeccc1497fd7b68c26e2a6 Mon Sep 17 00:00:00 2001 From: Andy Street Date: Wed, 18 Jan 2017 09:18:20 -0800 Subject: [PATCH] Improve error messages when nesting View in Text Summary: Since we don't support this, we should throw early. Also tries to improve the error message when adding a node that doesn't have a YogaNode to a node that can't measure itself. Reviewed By: andreicoman11 Differential Revision: D4421542 fbshipit-source-id: e0be8cdd763091145e5e6af2db91515f4d236b37 --- Libraries/Components/View/View.js | 10 ++++++++++ .../com/facebook/react/uimanager/ReactShadowNode.java | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index 2f7e21c78..91c4398ea 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -21,6 +21,8 @@ const ReactNativeViewAttributes = require('ReactNativeViewAttributes'); const StyleSheetPropType = require('StyleSheetPropType'); const ViewStylePropTypes = require('ViewStylePropTypes'); +const invariant = require('invariant'); + var TVViewPropTypes = {}; if (Platform.isTVOS) { TVViewPropTypes = require('TVViewPropTypes'); @@ -506,7 +508,15 @@ const View = React.createClass({ needsOffscreenAlphaCompositing: PropTypes.bool, }, + contextTypes: { + isInAParentText: React.PropTypes.bool, + }, + render: function() { + invariant( + !(this.context.isInAParentText && Platform.OS === 'android'), + 'Nesting of within is not supported on Android.'); + // 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 diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java index 838c3f490..74052a1d2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java @@ -167,7 +167,9 @@ public class ReactShadowNode { YogaNode childYogaNode = child.mYogaNode; if (childYogaNode == null) { throw new RuntimeException( - "Cannot add a child that doesn't have a CSS node to a node without a measure function!"); + "Cannot add a child that doesn't have a YogaNode to a parent without a measure " + + "function! (Trying to add a '" + child.getClass().getSimpleName() + "' to a '" + + getClass().getSimpleName() + "')"); } mYogaNode.addChildAt(childYogaNode, i); }