Introduce NO_SURFACE constant to specify the lack of surfaces used by legacy system (#36747)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36747

Introduce NO_SURFACE constant to specify the lack of surfaces used by legacy system

changelog: [internal] internal

Reviewed By: sshic

Differential Revision: D44563649

fbshipit-source-id: 99c7028c5ee508c2982cefc9b3199a332c2346c7
This commit is contained in:
David Vacca
2023-03-31 15:34:45 -07:00
committed by Facebook GitHub Bot
parent d2e591cb2b
commit d2d2a8a598
24 changed files with 64 additions and 36 deletions
@@ -44,6 +44,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"),
react_native_target("java/com/facebook/react/touch:touch"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/common:common"),
react_native_target("java/com/facebook/react/views/text:text"),
react_native_target("java/com/facebook/react/views/view:view"),
react_native_target("jni/react/fabric:jni"),
@@ -12,6 +12,7 @@ import androidx.annotation.Nullable;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.fabric.FabricUIManager;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.EventCategoryDef;
import com.facebook.react.uimanager.events.RCTModernEventEmitter;
import com.facebook.react.uimanager.events.TouchEvent;
@@ -20,8 +21,6 @@ import com.facebook.systrace.Systrace;
public class FabricEventEmitter implements RCTModernEventEmitter {
private static final String TAG = "FabricEventEmitter";
@NonNull private final FabricUIManager mUIManager;
public FabricEventEmitter(@NonNull FabricUIManager uiManager) {
@@ -30,7 +29,7 @@ public class FabricEventEmitter implements RCTModernEventEmitter {
@Override
public void receiveEvent(int reactTag, @NonNull String eventName, @Nullable WritableMap params) {
receiveEvent(-1, reactTag, eventName, params);
receiveEvent(ViewUtil.NO_SURFACE_ID, reactTag, eventName, params);
}
@Override
@@ -51,9 +50,12 @@ public class FabricEventEmitter implements RCTModernEventEmitter {
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricEventEmitter.receiveEvent('" + eventName + "')");
mUIManager.receiveEvent(
surfaceId, reactTag, eventName, canCoalesceEvent, customCoalesceKey, params, category);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
try {
mUIManager.receiveEvent(
surfaceId, reactTag, eventName, canCoalesceEvent, customCoalesceKey, params, category);
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
/** Touches are dispatched by {@link #receiveTouches(TouchEvent)} */
@@ -32,6 +32,7 @@ import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.uimanager.RootViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.yoga.YogaMeasureMode;
import java.util.Map;
import java.util.Queue;
@@ -280,12 +281,12 @@ public class MountingManager {
* Send an accessibility eventType to a Native View. eventType is any valid `AccessibilityEvent.X`
* value.
*
* <p>Why accept `-1` SurfaceId? Currently there are calls to UIManager.sendAccessibilityEvent
* which is a legacy API and accepts only reactTag. We will have to investigate and migrate away
* from those calls over time.
* <p>Why accept {@ViewUtils.NO_SURFACE_ID}(-1) SurfaceId? Currently there are calls to
* UIManager.sendAccessibilityEvent which is a legacy API and accepts only reactTag. We will have
* to investigate and migrate away from those calls over time.
*
* @param surfaceId {@link int} that identifies the surface or -1 to temporarily support backward
* compatibility.
* @param surfaceId {@link int} that identifies the surface or {@ViewUtils.NO_SURFACE_ID}(-1) to
* temporarily support backward compatibility.
* @param reactTag {@link int} that identifies the react Tag of the view.
* @param eventType {@link int} that identifies Android eventType. see {@link
* View#sendAccessibilityEvent}
@@ -326,7 +327,9 @@ public class MountingManager {
@ThreadConfined(ANY)
public @Nullable EventEmitterWrapper getEventEmitter(int surfaceId, int reactTag) {
SurfaceMountingManager surfaceMountingManager =
(surfaceId == -1 ? getSurfaceManagerForView(reactTag) : getSurfaceManager(surfaceId));
(surfaceId == ViewUtil.NO_SURFACE_ID
? getSurfaceManagerForView(reactTag)
: getSurfaceManager(surfaceId));
if (surfaceMountingManager == null) {
return null;
}
@@ -12,6 +12,8 @@ import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
public class ViewUtil {
public static final int NO_SURFACE_ID = -1;
/**
* Counter for uniquely identifying views. - % 2 === 0 means it is a Fabric tag. See
* https://github.com/facebook/react/pull/12587
@@ -9,6 +9,7 @@ package com.facebook.react.views.drawer.events;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
public class DrawerClosedEvent extends Event<DrawerClosedEvent> {
@@ -17,7 +18,7 @@ public class DrawerClosedEvent extends Event<DrawerClosedEvent> {
@Deprecated
public DrawerClosedEvent(int viewId) {
this(-1, viewId);
this(ViewUtil.NO_SURFACE_ID, viewId);
}
public DrawerClosedEvent(int surfaceId, int viewId) {
@@ -9,6 +9,7 @@ package com.facebook.react.views.drawer.events;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
public class DrawerOpenedEvent extends Event<DrawerOpenedEvent> {
@@ -17,7 +18,7 @@ public class DrawerOpenedEvent extends Event<DrawerOpenedEvent> {
@Deprecated
public DrawerOpenedEvent(int viewId) {
this(-1, viewId);
this(ViewUtil.NO_SURFACE_ID, viewId);
}
public DrawerOpenedEvent(int surfaceId, int viewId) {
@@ -9,6 +9,7 @@ package com.facebook.react.views.drawer.events;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by a DrawerLayout as it is being moved open/closed. */
@@ -20,7 +21,7 @@ public class DrawerSlideEvent extends Event<DrawerSlideEvent> {
@Deprecated
public DrawerSlideEvent(int viewId, float offset) {
this(-1, viewId, offset);
this(ViewUtil.NO_SURFACE_ID, viewId, offset);
}
public DrawerSlideEvent(int surfaceId, int viewId, float offset) {
@@ -9,6 +9,7 @@ package com.facebook.react.views.drawer.events;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
public class DrawerStateChangedEvent extends Event<DrawerStateChangedEvent> {
@@ -19,7 +20,7 @@ public class DrawerStateChangedEvent extends Event<DrawerStateChangedEvent> {
@Deprecated
public DrawerStateChangedEvent(int viewId, int drawerState) {
this(-1, viewId, drawerState);
this(ViewUtil.NO_SURFACE_ID, viewId, drawerState);
}
public DrawerStateChangedEvent(int surfaceId, int viewId, int drawerState) {
@@ -11,6 +11,7 @@ import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -36,29 +37,29 @@ public class ImageLoadEvent extends Event<ImageLoadEvent> {
@Deprecated
public static final ImageLoadEvent createLoadStartEvent(int viewId) {
return createLoadStartEvent(-1, viewId);
return createLoadStartEvent(ViewUtil.NO_SURFACE_ID, viewId);
}
@Deprecated
public static final ImageLoadEvent createProgressEvent(
int viewId, @Nullable String imageUri, int loaded, int total) {
return createProgressEvent(-1, viewId, imageUri, loaded, total);
return createProgressEvent(ViewUtil.NO_SURFACE_ID, viewId, imageUri, loaded, total);
}
@Deprecated
public static final ImageLoadEvent createLoadEvent(
int viewId, @Nullable String imageUri, int width, int height) {
return createLoadEvent(-1, viewId, imageUri, width, height);
return createLoadEvent(ViewUtil.NO_SURFACE_ID, viewId, imageUri, width, height);
}
@Deprecated
public static final ImageLoadEvent createErrorEvent(int viewId, Throwable throwable) {
return createErrorEvent(-1, viewId, throwable);
return createErrorEvent(ViewUtil.NO_SURFACE_ID, viewId, throwable);
}
@Deprecated
public static final ImageLoadEvent createLoadEndEvent(int viewId) {
return createLoadEndEvent(-1, viewId);
return createLoadEndEvent(ViewUtil.NO_SURFACE_ID, viewId);
}
public static final ImageLoadEvent createLoadStartEvent(int surfaceId, int viewId) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.modal;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** {@link Event} for dismissing a Dialog. */
@@ -19,7 +20,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
protected RequestCloseEvent(int viewTag) {
this(-1, viewTag);
this(ViewUtil.NO_SURFACE_ID, viewTag);
}
protected RequestCloseEvent(int surfaceId, int viewTag) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.modal;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** {@link Event} for showing a Dialog. */
@@ -19,7 +20,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
protected ShowEvent(int viewTag) {
this(-1, viewTag);
this(ViewUtil.NO_SURFACE_ID, viewTag);
}
protected ShowEvent(int surfaceId, int viewTag) {
@@ -14,6 +14,7 @@ import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** A event dispatched from a ScrollView scrolling. */
@@ -46,7 +47,7 @@ public class ScrollEvent extends Event<ScrollEvent> {
int scrollViewWidth,
int scrollViewHeight) {
return obtain(
-1,
ViewUtil.NO_SURFACE_ID,
viewTag,
scrollEventType,
scrollX,
@@ -10,13 +10,14 @@ package com.facebook.react.views.swiperefresh;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
public class RefreshEvent extends Event<RefreshEvent> {
@Deprecated
protected RefreshEvent(int viewTag) {
this(-1, viewTag);
this(ViewUtil.NO_SURFACE_ID, viewTag);
}
protected RefreshEvent(int surfaceId, int viewTag) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.switchview;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by a ReactSwitchManager once a switch is fully switched on/off */
@@ -21,7 +22,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
public ReactSwitchEvent(int viewId, boolean isChecked) {
this(-1, viewId, isChecked);
this(ViewUtil.NO_SURFACE_ID, viewId, isChecked);
}
public ReactSwitchEvent(int surfaceId, int viewId, boolean isChecked) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by EditText native view when content size changes. */
@@ -22,7 +23,7 @@ public class ReactContentSizeChangedEvent extends Event<ReactTextChangedEvent> {
@Deprecated
public ReactContentSizeChangedEvent(int viewId, float contentSizeWidth, float contentSizeHeight) {
this(-1, viewId, contentSizeWidth, contentSizeHeight);
this(ViewUtil.NO_SURFACE_ID, viewId, contentSizeWidth, contentSizeHeight);
}
public ReactContentSizeChangedEvent(
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/**
@@ -25,7 +26,7 @@ public class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {
@Deprecated
public ReactTextChangedEvent(int viewId, String text, int eventCount) {
this(-1, viewId, text, eventCount);
this(ViewUtil.NO_SURFACE_ID, viewId, text, eventCount);
}
public ReactTextChangedEvent(int surfaceId, int viewId, String text, int eventCount) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by EditText native view when it loses focus. */
@@ -19,7 +20,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
public ReactTextInputBlurEvent(int viewId) {
this(-1, viewId);
this(ViewUtil.NO_SURFACE_ID, viewId);
}
public ReactTextInputBlurEvent(int surfaceId, int viewId) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/**
@@ -24,7 +25,7 @@ class ReactTextInputEndEditingEvent extends Event<ReactTextInputEndEditingEvent>
@Deprecated
public ReactTextInputEndEditingEvent(int viewId, String text) {
this(-1, viewId, text);
this(ViewUtil.NO_SURFACE_ID, viewId, text);
}
public ReactTextInputEndEditingEvent(int surfaceId, int viewId, String text) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/**
@@ -28,7 +29,7 @@ public class ReactTextInputEvent extends Event<ReactTextInputEvent> {
@Deprecated
public ReactTextInputEvent(
int viewId, String text, String previousText, int rangeStart, int rangeEnd) {
this(-1, viewId, text, previousText, rangeStart, rangeEnd);
this(ViewUtil.NO_SURFACE_ID, viewId, text, previousText, rangeStart, rangeEnd);
}
public ReactTextInputEvent(
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by EditText native view when it receives focus. */
@@ -19,7 +20,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
public ReactTextInputFocusEvent(int viewId) {
this(-1, viewId);
this(ViewUtil.NO_SURFACE_ID, viewId);
}
public ReactTextInputFocusEvent(int surfaceId, int viewId) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by EditText native view when key pressed */
@@ -21,7 +22,7 @@ public class ReactTextInputKeyPressEvent extends Event<ReactTextInputEvent> {
@Deprecated
ReactTextInputKeyPressEvent(int viewId, final String key) {
this(-1, viewId, key);
this(ViewUtil.NO_SURFACE_ID, viewId, key);
}
ReactTextInputKeyPressEvent(int surfaceId, int viewId, final String key) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by EditText native view when the text selection changes. */
@@ -22,7 +23,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
public ReactTextInputSelectionEvent(int viewId, int selectionStart, int selectionEnd) {
this(-1, viewId, selectionStart, selectionEnd);
this(ViewUtil.NO_SURFACE_ID, viewId, selectionStart, selectionEnd);
}
public ReactTextInputSelectionEvent(
@@ -10,6 +10,7 @@ package com.facebook.react.views.textinput;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Event emitted by EditText native view when the user submits the text. */
@@ -22,7 +23,7 @@ import com.facebook.react.uimanager.events.Event;
@Deprecated
public ReactTextInputSubmitEditingEvent(int viewId, String text) {
this(-1, viewId, text);
this(ViewUtil.NO_SURFACE_ID, viewId, text);
}
public ReactTextInputSubmitEditingEvent(int surfaceId, int viewId, String text) {
@@ -10,6 +10,7 @@ package com.facebook.react.views.view;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.common.ViewUtil;
import com.facebook.react.uimanager.events.Event;
/** Represents a Click on the ReactViewGroup */
@@ -18,7 +19,7 @@ public class ViewGroupClickEvent extends Event<ViewGroupClickEvent> {
@Deprecated
public ViewGroupClickEvent(int viewId) {
this(-1, viewId);
this(ViewUtil.NO_SURFACE_ID, viewId);
}
public ViewGroupClickEvent(int surfaceId, int viewId) {