Log java error messages from FabricUIManagerModule

Reviewed By: mdvacca

Differential Revision: D7126177

fbshipit-source-id: bafa6e2b3dabf39d2ca0d9a8830b877fc5ae97ec
This commit is contained in:
Andrew Chen (Eng) 2018-03-01 12:04:23 -08:00 committed by Facebook Github Bot
parent 9b3861c109
commit 3f85dc5337
1 changed files with 83 additions and 37 deletions

View File

@ -58,7 +58,7 @@ public class FabricUIManagerModule implements UIManager {
String viewName,
int rootTag,
ReadableNativeMap props) {
try {
ViewManager viewManager = mViewManagerRegistry.get(viewName);
ReactShadowNode node = viewManager.createShadowNodeInstance(mReactApplicationContext);
ReactShadowNode rootNode = getRootNode(rootTag);
@ -71,6 +71,10 @@ public class FabricUIManagerModule implements UIManager {
mUIViewOperationQueue
.enqueueCreateView(rootNode.getThemedContext(), reactTag, viewName, styles);
return node;
} catch (Exception e) {
handleException(rootTag, e);
return null;
}
}
private ReactShadowNode getRootNode(int rootTag) {
@ -93,9 +97,14 @@ public class FabricUIManagerModule implements UIManager {
*/
@Nullable
public ReactShadowNode cloneNode(ReactShadowNode node) {
try {
ReactShadowNode clone = node.mutableCopy();
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Exception e) {
handleException(node.getThemedContext(), e);
return null;
}
}
/**
@ -105,9 +114,14 @@ public class FabricUIManagerModule implements UIManager {
*/
@Nullable
public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node) {
try {
ReactShadowNode clone = node.mutableCopyWithNewChildren();
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Exception e) {
handleException(node.getThemedContext(), e);
return null;
}
}
/**
@ -119,10 +133,15 @@ public class FabricUIManagerModule implements UIManager {
public ReactShadowNode cloneNodeWithNewProps(
ReactShadowNode node,
@Nullable ReadableNativeMap newProps) {
try {
ReactShadowNode clone = node.mutableCopy();
updateProps(clone, newProps);
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Exception e) {
handleException(node.getThemedContext(), e);
return null;
}
}
/**
@ -135,10 +154,16 @@ public class FabricUIManagerModule implements UIManager {
public ReactShadowNode cloneNodeWithNewChildrenAndProps(
ReactShadowNode node,
ReadableNativeMap newProps) {
try {
ReactShadowNode clone = node.mutableCopyWithNewChildren();
updateProps(clone, newProps);
assertReactShadowNodeCopy(node, clone);
return clone;
} catch (Exception e) {
handleException(node.getThemedContext(), e);
getRootNode(1).getThemedContext().handleException(e);
return null;
}
}
private void assertReactShadowNodeCopy(ReactShadowNode source, ReactShadowNode target) {
@ -153,8 +178,12 @@ public class FabricUIManagerModule implements UIManager {
*/
@Nullable
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
try {
parent.addChildAt(child, parent.getChildCount());
setChildren(parent.getReactTag(), child.getReactTag());
} catch (Exception e) {
handleException(parent.getThemedContext(), e);
}
}
/**
@ -173,6 +202,7 @@ public class FabricUIManagerModule implements UIManager {
}
public void completeRoot(int rootTag, List<ReactShadowNode> childList) {
try {
if (!childList.isEmpty()) {
ReactShadowNode rootNode = getRootNode(rootTag);
for (int i = 0; i < childList.size(); i++) {
@ -183,7 +213,11 @@ public class FabricUIManagerModule implements UIManager {
calculateRootLayout(rootNode);
applyUpdatesRecursive(rootNode, 0, 0);
mUIViewOperationQueue.dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis());
mUIViewOperationQueue
.dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis());
}
} catch (Exception e) {
handleException(rootTag, e);
}
}
@ -297,4 +331,16 @@ public class FabricUIManagerModule implements UIManager {
}
}
private void handleException(ThemedReactContext context, Exception e) {
try {
context.handleException(e);
} catch (Exception ex) {
Log.e(TAG, "Exception while executing a Fabric method", e);
throw new RuntimeException(ex.getMessage(), e);
}
}
private void handleException(int rootTag, Exception e) {
handleException(getRootNode(rootTag).getThemedContext(), e);
}
}