From 96cb8165c8ec05aaa746cbec4ab19f3526bb6a37 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Fri, 13 May 2016 16:31:24 -0700 Subject: [PATCH] Fix setJSResponder Nodes crash Summary: Nodes crashed when setJSResponder was called on a virtual (non-View) node, because a View could not be found using that react tag. The solution is two fold - first, to figure out the View parent and pass that to setJSResponder in addition to that of the virtual tag. Secondly, we weren't mounting views that had animation properties (transform, for example) to Views, which caused related code to fail. Reviewed By: sriramramani Differential Revision: D3301310 --- .../java/com/facebook/react/flat/FlatShadowNode.java | 2 ++ .../com/facebook/react/flat/FlatUIImplementation.java | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java index a8c7d6a4c..b73b533d8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatShadowNode.java @@ -35,6 +35,7 @@ import com.facebook.react.uimanager.annotations.ReactProp; private static final String PROP_ACCESSIBILITY_LIVE_REGION = "accessibilityLiveRegion"; private static final String PROP_IMPORTANT_FOR_ACCESSIBILITY = "importantForAccessibility"; private static final String PROP_TEST_ID = "testID"; + private static final String PROP_TRANSFORM = "transform"; private DrawCommand[] mDrawCommands = DrawCommand.EMPTY_ARRAY; private AttachDetachListener[] mAttachDetachListeners = AttachDetachListener.EMPTY_ARRAY; @@ -72,6 +73,7 @@ import com.facebook.react.uimanager.annotations.ReactProp; styles.hasKey(PROP_ACCESSIBILITY_LABEL) || styles.hasKey(PROP_ACCESSIBILITY_COMPONENT_TYPE) || styles.hasKey(PROP_ACCESSIBILITY_LIVE_REGION) || + styles.hasKey(PROP_TRANSFORM) || styles.hasKey(PROP_IMPORTANT_FOR_ACCESSIBILITY)) { forceMountToView(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java index f149bb8b8..99a4b7e1f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java @@ -465,10 +465,18 @@ public class FlatUIImplementation extends UIImplementation { while (node.isVirtual()) { node = node.getParent(); } + int tag = node.getReactTag(); + + // if the node in question doesn't mount to a View, find the first parent that does mount to + // a View. without this, we'll crash when we try to set the JSResponder, since part of that + // is to find the parent view and ask it to not intercept touch events. + while (node instanceof FlatShadowNode && !((FlatShadowNode) node).mountsToView()) { + node = node.getParent(); + } FlatUIViewOperationQueue operationsQueue = mStateBuilder.getOperationsQueue(); operationsQueue.enqueueSetJSResponder( - node.getReactTag(), + node == null ? tag : node.getReactTag(), possiblyVirtualReactTag, blockNativeResponder); }