Add extra information to error message reported when a ReactRawText is included as a child of a non Text component

Reviewed By: achen1

Differential Revision: D7120188

fbshipit-source-id: 553a26d04a62dceb86d791bcdcb3a5e16a12f64b
This commit is contained in:
David Vacca 2018-03-01 16:45:03 -08:00 committed by Facebook Github Bot
parent 3f85dc5337
commit 22990c3ce7
3 changed files with 21 additions and 9 deletions

View File

@ -187,6 +187,11 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
boolean isDescendantOf(T ancestorNode);
/**
* @return a {@link String} representation of the Yoga hierarchy of this {@link ReactShadowNode}
*/
String getHierarchyInfo();
/*
* In some cases we need a way to specify some environmental data to shadow node
* to improve layout (or do something similar), so {@code localData} serves these needs.
@ -197,7 +202,7 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
* Use {@link UIManagerModule#setViewLocalData} to set this property
* (to provide local/environmental data for a shadow node) from the main thread.
*/
public void setLocalData(Object data);
void setLocalData(Object data);
/**
* Returns the offset within the native children owned by all layout-only nodes in the subtree

View File

@ -9,7 +9,6 @@ package com.facebook.react.uimanager;
import static java.lang.System.arraycopy;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
import com.facebook.yoga.YogaAlign;
import com.facebook.yoga.YogaBaselineFunction;
@ -235,9 +234,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
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.getClass().getSimpleName()
+ child.toString()
+ "' to a '"
+ getClass().getSimpleName()
+ toString()
+ "')");
}
mYogaNode.addChildAt(childYogaNode, i);
@ -570,6 +569,11 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
return isDescendant;
}
@Override
public String toString() {
return mViewClassName;
}
/*
* In some cases we need a way to specify some environmental data to shadow node
* to improve layout (or do something similar), so {@code localData} serves these needs.
@ -962,13 +966,13 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
@Override
public String toString() {
public String getHierarchyInfo() {
StringBuilder sb = new StringBuilder();
toStringWithIndentation(sb, 0);
getHierarchyInfoWithIndentation(sb, 0);
return sb.toString();
}
private void toStringWithIndentation(StringBuilder result, int level) {
private void getHierarchyInfoWithIndentation(StringBuilder result, int level) {
// Spaces and tabs are dropped by IntelliJ logcat integration, so rely on __ instead.
for (int i = 0; i < level; ++i) {
result.append("__");
@ -987,7 +991,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).toStringWithIndentation(result, level + 1);
getChildAt(i).getHierarchyInfoWithIndentation(result, level + 1);
}
}

View File

@ -49,5 +49,8 @@ public class ReactRawTextShadowNode extends ReactShadowNodeImpl {
return true;
}
@Override
public String toString() {
return getViewClass() + " [text: " + mText + "]";
}
}