Skip to content

Commit

Permalink
Add specific exception for rendering raw text outside of <Text>
Browse files Browse the repository at this point in the history
This matched the iOS implementation and is a more explicit exception for the most common case.
  • Loading branch information
yedidyak committed Oct 30, 2018
1 parent 31bb551 commit 956d020
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <Text> 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);
}
Expand Down

0 comments on commit 956d020

Please sign in to comment.