Skip to content

Commit ab5e87f

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Pretty-print Native AnimatedNode values
Summary: For debugging, add prettyPrint method to AnimatedNode classes. Changelog: [Internal] Reviewed By: shergin Differential Revision: D22752292 fbshipit-source-id: ce1f08fc4fd97f38629dd82151c6ea762026c7c9
1 parent 8d613c6 commit ab5e87f

13 files changed

+130
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/animated/AdditionAnimatedNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ public void update() {
4343
}
4444
}
4545
}
46+
47+
@Override
48+
public String prettyPrint() {
49+
return "AdditionAnimatedNode["
50+
+ mTag
51+
+ "]: input nodes: "
52+
+ (mInputNodes != null ? mInputNodes.toString() : "null")
53+
+ " - super: "
54+
+ super.prettyPrint();
55+
}
4656
}

ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNode.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,20 @@ public void onDetachedFromNode(AnimatedNode parent) {}
5757
* it can be used to calculate node's value.
5858
*/
5959
public void update() {}
60+
61+
/**
62+
* Pretty-printer for the AnimatedNode. Only called in production pre-crash for debug diagnostics.
63+
*/
64+
public abstract String prettyPrint();
65+
66+
public String prettyPrintWithChildren() {
67+
String children = "";
68+
if (mChildren != null && mChildren.size() > 0) {
69+
for (AnimatedNode child : mChildren) {
70+
children += " " + child.mTag;
71+
}
72+
}
73+
74+
return prettyPrint() + (children.length() > 0 ? " children: " + children : "");
75+
}
6076
}

ReactAndroid/src/main/java/com/facebook/react/animated/DiffClampAnimatedNode.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ private double getInputNodeValue() {
4646

4747
return ((ValueAnimatedNode) animatedNode).getValue();
4848
}
49+
50+
public String prettyPrint() {
51+
return "DiffClampAnimatedNode["
52+
+ mTag
53+
+ "]: InputNodeTag: "
54+
+ mInputNodeTag
55+
+ " min: "
56+
+ mMin
57+
+ " max: "
58+
+ mMax
59+
+ " lastValue: "
60+
+ mLastValue
61+
+ " super: "
62+
+ super.prettyPrint();
63+
}
4964
}

ReactAndroid/src/main/java/com/facebook/react/animated/DivisionAnimatedNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,14 @@ public void update() {
5151
}
5252
}
5353
}
54+
55+
@Override
56+
public String prettyPrint() {
57+
return "DivisionAnimatedNode["
58+
+ mTag
59+
+ "]: input nodes: "
60+
+ (mInputNodes != null ? mInputNodes.toString() : "null")
61+
+ " - super: "
62+
+ super.prettyPrint();
63+
}
5464
}

ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,8 @@ public void update() {
249249
}
250250
}
251251
}
252+
253+
public String prettyPrint() {
254+
return "InterpolationAnimatedNode[" + mTag + "] super: " + super.prettyPrint();
255+
}
252256
}

ReactAndroid/src/main/java/com/facebook/react/animated/ModulusAnimatedNode.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ public void update() {
3434
"Illegal node ID set as an input for " + "Animated.modulus node");
3535
}
3636
}
37+
38+
public String prettyPrint() {
39+
return "NativeAnimatedNodesManager["
40+
+ mTag
41+
+ "] inputNode: "
42+
+ mInputNode
43+
+ " modulus: "
44+
+ mModulus
45+
+ " super: "
46+
+ super.prettyPrint();
47+
}
3748
}

ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ public void update() {
4343
}
4444
}
4545
}
46+
47+
@Override
48+
public String prettyPrint() {
49+
return "MultiplicationAnimatedNode["
50+
+ mTag
51+
+ "]: input nodes: "
52+
+ (mInputNodes != null ? mInputNodes.toString() : "null")
53+
+ " - super: "
54+
+ super.prettyPrint();
55+
}
4656
}

ReactAndroid/src/main/java/com/facebook/react/animated/PropsAnimatedNode.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,15 @@ public final void updateView() {
113113

114114
mUIManager.synchronouslyUpdateViewOnUIThread(mConnectedViewTag, mPropMap);
115115
}
116+
117+
public String prettyPrint() {
118+
return "PropsAnimatedNode["
119+
+ mTag
120+
+ "] connectedViewTag: "
121+
+ mConnectedViewTag
122+
+ " mPropNodeMapping: "
123+
+ (mPropNodeMapping != null ? mPropNodeMapping.toString() : "null")
124+
+ " mPropMap: "
125+
+ (mPropMap != null ? mPropMap.toString() : "null");
126+
}
116127
}

ReactAndroid/src/main/java/com/facebook/react/animated/StyleAnimatedNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@ public void collectViewUpdates(JavaOnlyMap propsMap) {
4949
}
5050
}
5151
}
52+
53+
public String prettyPrint() {
54+
return "StyleAnimatedNode["
55+
+ mTag
56+
+ "] mPropMapping: "
57+
+ (mPropMapping != null ? mPropMapping.toString() : "null");
58+
}
5259
}

ReactAndroid/src/main/java/com/facebook/react/animated/SubtractionAnimatedNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@ public void update() {
4747
}
4848
}
4949
}
50+
51+
@Override
52+
public String prettyPrint() {
53+
return "SubtractionAnimatedNode["
54+
+ mTag
55+
+ "]: input nodes: "
56+
+ (mInputNodes != null ? mInputNodes.toString() : "null")
57+
+ " - super: "
58+
+ super.prettyPrint();
59+
}
5060
}

0 commit comments

Comments
 (0)