From d0b79346f1b220a4f4bb83e988dcad3b4339a7be Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Mon, 29 Oct 2018 13:01:04 +0200 Subject: [PATCH] Add specific exception for rendering raw text outside of This matched the iOS implementation and is a more explicit exception for the most common case. --- .../react/uimanager/ReactShadowNodeImpl.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java index 2f459eccc12d5c..2a48c39eb7604b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -13,6 +13,7 @@ import com.facebook.infer.annotation.Assertions; import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.uimanager.annotations.ReactPropertyHolder; +import com.facebook.react.views.text.ReactRawTextShadowNode; import com.facebook.yoga.YogaAlign; import com.facebook.yoga.YogaBaselineFunction; import com.facebook.yoga.YogaConfig; @@ -226,13 +227,21 @@ public void addChildAt(ReactShadowNodeImpl child, int i) { if (mYogaNode != null && !isYogaLeafNode()) { YogaNode childYogaNode = child.mYogaNode; if (childYogaNode == null) { - throw new RuntimeException( - "Cannot add a child that doesn't have a YogaNode to a parent without a measure " - + "function! (Trying to add a '" - + child.toString() - + "' to a '" - + toString() - + "')"); + + if (child instanceof ReactRawTextShadowNode) { + throw new RuntimeException( + "Raw text cannot be used outside of a tag. Not rendering string: '" + + ((ReactRawTextShadowNode) child).getText() + + "'"); + } else { + throw new RuntimeException( + "Cannot add a child that doesn't have a YogaNode to a parent without a measure " + + "function! (Trying to add a '" + + child.toString() + + "' to a '" + + toString() + + "')"); + } } mYogaNode.addChildAt(childYogaNode, i); }