mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support RootView in UIManagerHelper.getSurfaceId
Summary: The `Event.getSurfaceIdForView` method I added recently is actually a duplicate of `UIManagerHelper.getSurfaceId`, except that the latter doesn't support RootViews very well. Changelog: [Android][Changed] - Improved UIManagerHelper.getSurfaceId and removed Event.getSurfaceIdForView Reviewed By: JoshuaGross, mdvacca Differential Revision: D32102175 fbshipit-source-id: 01741df6b646037a4575e9ca302ea248af9fd6f3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
74b91c5073
commit
954fc04f58
@@ -12,7 +12,6 @@ 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.events.Event;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.uimanager.events.TouchEvent;
|
||||
import com.facebook.react.uimanager.events.TouchEventCoalescingKeyHelper;
|
||||
@@ -75,7 +74,7 @@ public class JSTouchDispatcher {
|
||||
mTargetTag = findTargetTagAndSetCoordinates(ev);
|
||||
eventDispatcher.dispatchEvent(
|
||||
TouchEvent.obtain(
|
||||
Event.getSurfaceIdForView(mRootViewGroup),
|
||||
UIManagerHelper.getSurfaceId(mRootViewGroup),
|
||||
mTargetTag,
|
||||
TouchEventType.START,
|
||||
ev,
|
||||
@@ -100,7 +99,7 @@ public class JSTouchDispatcher {
|
||||
findTargetTagAndSetCoordinates(ev);
|
||||
eventDispatcher.dispatchEvent(
|
||||
TouchEvent.obtain(
|
||||
Event.getSurfaceIdForView(mRootViewGroup),
|
||||
UIManagerHelper.getSurfaceId(mRootViewGroup),
|
||||
mTargetTag,
|
||||
TouchEventType.END,
|
||||
ev,
|
||||
@@ -115,7 +114,7 @@ public class JSTouchDispatcher {
|
||||
findTargetTagAndSetCoordinates(ev);
|
||||
eventDispatcher.dispatchEvent(
|
||||
TouchEvent.obtain(
|
||||
Event.getSurfaceIdForView(mRootViewGroup),
|
||||
UIManagerHelper.getSurfaceId(mRootViewGroup),
|
||||
mTargetTag,
|
||||
TouchEventType.MOVE,
|
||||
ev,
|
||||
@@ -127,7 +126,7 @@ public class JSTouchDispatcher {
|
||||
// New pointer goes down, this can only happen after ACTION_DOWN is sent for the first pointer
|
||||
eventDispatcher.dispatchEvent(
|
||||
TouchEvent.obtain(
|
||||
Event.getSurfaceIdForView(mRootViewGroup),
|
||||
UIManagerHelper.getSurfaceId(mRootViewGroup),
|
||||
mTargetTag,
|
||||
TouchEventType.START,
|
||||
ev,
|
||||
@@ -139,7 +138,7 @@ public class JSTouchDispatcher {
|
||||
// Exactly one of the pointers goes up
|
||||
eventDispatcher.dispatchEvent(
|
||||
TouchEvent.obtain(
|
||||
Event.getSurfaceIdForView(mRootViewGroup),
|
||||
UIManagerHelper.getSurfaceId(mRootViewGroup),
|
||||
mTargetTag,
|
||||
TouchEventType.END,
|
||||
ev,
|
||||
@@ -188,7 +187,7 @@ public class JSTouchDispatcher {
|
||||
Assertions.assertNotNull(eventDispatcher)
|
||||
.dispatchEvent(
|
||||
TouchEvent.obtain(
|
||||
Event.getSurfaceIdForView(mRootViewGroup),
|
||||
UIManagerHelper.getSurfaceId(mRootViewGroup),
|
||||
mTargetTag,
|
||||
TouchEventType.CANCEL,
|
||||
androidEvent,
|
||||
|
||||
@@ -160,10 +160,18 @@ public class UIManagerHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Get the ThemedReactContext associated with a View, if possible, and then call
|
||||
* getSurfaceId on it. See above (getReactContext) for additional context.
|
||||
* @return Gets the surfaceId for the {@link ThemedReactContext} associated with a View, if
|
||||
* possible, and then call getSurfaceId on it. See above (getReactContext) for additional
|
||||
* context.
|
||||
* <p>For RootViews, the root's rootViewTag is returned
|
||||
* <p>Returns -1 for non-Fabric views
|
||||
*/
|
||||
public static int getSurfaceId(View view) {
|
||||
if (view instanceof ReactRoot) {
|
||||
ReactRoot rootView = (ReactRoot) view;
|
||||
return rootView.getUIManagerType() == UIManagerType.FABRIC ? rootView.getRootViewTag() : -1;
|
||||
}
|
||||
|
||||
int reactTag = view.getId();
|
||||
|
||||
// In non-Fabric we don't have (or use) SurfaceId
|
||||
@@ -177,9 +185,8 @@ public class UIManagerHelper {
|
||||
}
|
||||
|
||||
int surfaceId = getSurfaceId(context);
|
||||
|
||||
// All Fabric-managed Views (should) have a ThemedReactContext attached.
|
||||
if (surfaceId == -1) {
|
||||
// All Fabric-managed Views (should) have a ThemedReactContext attached.
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new IllegalStateException(
|
||||
|
||||
@@ -7,13 +7,10 @@
|
||||
|
||||
package com.facebook.react.uimanager.events;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.common.SystemClock;
|
||||
import com.facebook.react.uimanager.IllegalViewOperationException;
|
||||
import com.facebook.react.uimanager.ReactRoot;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.common.UIManagerType;
|
||||
|
||||
/**
|
||||
@@ -43,23 +40,6 @@ public abstract class Event<T extends Event> {
|
||||
private long mTimestampMs;
|
||||
private int mUniqueID = sUniqueID++;
|
||||
|
||||
/**
|
||||
* This surfaceId should be a valid SurfaceId in Fabric, and should ALWAYS return -1 in
|
||||
* non-Fabric.
|
||||
*/
|
||||
public static int getSurfaceIdForView(@Nullable View view) {
|
||||
if (view != null
|
||||
&& view instanceof ReactRoot
|
||||
&& ((ReactRoot) view).getUIManagerType() == UIManagerType.FABRIC) {
|
||||
if (view.getContext() instanceof ThemedReactContext) {
|
||||
ThemedReactContext context = (ThemedReactContext) view.getContext();
|
||||
return context.getSurfaceId();
|
||||
}
|
||||
return ((ReactRoot) view).getRootViewTag();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected Event() {}
|
||||
|
||||
@Deprecated
|
||||
|
||||
Reference in New Issue
Block a user