Make ReactShadowNode's toString useful

Reviewed By: AaaChiuuu

Differential Revision: D5054307

fbshipit-source-id: af548077e9efabcdd9d86c3c06f6408a022762b8
This commit is contained in:
Andrew Y. Chen 2017-05-16 11:05:11 -07:00 committed by Facebook Github Bot
parent 06993fb780
commit 4a225f79a3
1 changed files with 29 additions and 3 deletions

View File

@ -777,11 +777,37 @@ public class ReactShadowNode {
@Override
public String toString() {
if (mYogaNode != null) {
return mYogaNode.toString();
StringBuilder sb = new StringBuilder();
toStringWithIndentation(sb, 0);
return sb.toString();
}
return getClass().getSimpleName() + " (virtual node)";
private void toStringWithIndentation(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("__");
}
result
.append(getClass().getSimpleName())
.append(" ");
if (mYogaNode != null) {
result
.append(getLayoutWidth())
.append(",")
.append(getLayoutHeight());
} else {
result.append("(virtual node)");
}
result.append("\n");
if (getChildCount() == 0) {
return;
}
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).toStringWithIndentation(result, level + 1);
}
}
public void dispose() {