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
This commit is contained in:
Ahmed El-Helw 2016-05-13 16:31:24 -07:00
parent 273c2e539c
commit 96cb8165c8
2 changed files with 11 additions and 1 deletions

View File

@ -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();
}

View File

@ -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);
}