Make sure that touch events have a SurfaceId only in Fabric

Summary:
Could fix some infrequent crashes in non-Fabric.

Changelog: [Internal]

Reviewed By: ShikaSD

Differential Revision: D28605773

fbshipit-source-id: 57555e013657e61cfb02b25d9fd14c9c15774e0e
This commit is contained in:
Joshua Gross
2021-05-21 11:32:02 -07:00
committed by Facebook GitHub Bot
parent 118489f6e5
commit cd4bebb6c6
@@ -12,6 +12,7 @@ import android.view.ViewGroup;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.TouchEvent;
import com.facebook.react.uimanager.events.TouchEventCoalescingKeyHelper;
@@ -50,14 +51,22 @@ public class JSTouchDispatcher {
mTargetTag = -1;
}
/**
* See Event.java. By contract, this surfaceId should be a valid SurfaceId in Fabric, and should
* ALWAYS return -1 in non-Fabric.
*
* @return
*/
private int getSurfaceId() {
if (mRootViewGroup instanceof ReactRoot) {
if (mRootViewGroup != null
&& mRootViewGroup instanceof ReactRoot
&& ((ReactRoot) mRootViewGroup).getUIManagerType() == UIManagerType.FABRIC) {
if (mRootViewGroup.getContext() instanceof ThemedReactContext) {
ThemedReactContext context = (ThemedReactContext) mRootViewGroup.getContext();
return context.getSurfaceId();
}
return ((ReactRoot) mRootViewGroup).getRootViewTag();
}
if (mRootViewGroup != null && mRootViewGroup.getContext() instanceof ThemedReactContext) {
ThemedReactContext context = (ThemedReactContext) mRootViewGroup.getContext();
return context.getSurfaceId();
}
return -1;
}