Skip to content

Commit 4e5d45f

Browse files
javachemeta-codesync[bot]
authored andcommitted
Deprecate getEventDispatcher variants (#55779)
Summary: Pull Request resolved: #55779 Cleanup this UIManagerHelper helper - now that we're fully on the new arch this can be simplified. Changelog: [Android][Breaking] Deprecated UIManagerHelper.getEventDispatcherForReactTag and UIManagerHelper.getEventDispatcher(ReactContext, UIManagerType Int), use getEventDispatcher Reviewed By: sammy-SC Differential Revision: D94514934 fbshipit-source-id: b28e6e18459b35a2309da98816e912040eb638ea
1 parent e5d2d95 commit 4e5d45f

23 files changed

Lines changed: 42 additions & 199 deletions

File tree

packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ReactPopupMenuContainer(context: Context) : FrameLayout(context) {
3434
}
3535
popupMenu.setOnMenuItemClickListener { menuItem ->
3636
val reactContext = context as ReactContext
37-
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
37+
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
3838
if (eventDispatcher != null) {
3939
val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
4040
eventDispatcher.dispatchEvent(PopupMenuSelectionEvent(surfaceId, id, menuItem.order))
@@ -43,7 +43,7 @@ public class ReactPopupMenuContainer(context: Context) : FrameLayout(context) {
4343
}
4444
popupMenu.setOnDismissListener {
4545
val reactContext = context as ReactContext
46-
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
46+
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
4747
if (eventDispatcher != null) {
4848
val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
4949
eventDispatcher.dispatchEvent(PopupMenuDismissEvent(surfaceId, id))

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,6 +4324,7 @@ public final class com/facebook/react/uimanager/UIManagerHelper {
43244324
public static final field PADDING_START_INDEX I
43254325
public static final field PADDING_TOP_INDEX I
43264326
public static final fun getDefaultTextInputPadding (Landroid/content/Context;)[F
4327+
public static final fun getEventDispatcher (Lcom/facebook/react/bridge/ReactContext;)Lcom/facebook/react/uimanager/events/EventDispatcher;
43274328
public static final fun getEventDispatcher (Lcom/facebook/react/bridge/ReactContext;I)Lcom/facebook/react/uimanager/events/EventDispatcher;
43284329
public static final fun getEventDispatcherForReactTag (Lcom/facebook/react/bridge/ReactContext;I)Lcom/facebook/react/uimanager/events/EventDispatcher;
43294330
public static final fun getReactContext (Landroid/view/View;)Lcom/facebook/react/bridge/ReactContext;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ public void onChildStartedNativeGesture(View childView, MotionEvent ev) {
213213
return;
214214
}
215215

216-
EventDispatcher eventDispatcher =
217-
UIManagerHelper.getEventDispatcher(reactContext, getUIManagerType());
216+
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext);
218217
if (eventDispatcher != null) {
219218
mJSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher, reactContext);
220219
if (childView != null && mJSPointerDispatcher != null) {
@@ -229,8 +228,7 @@ public void onChildEndedNativeGesture(View childView, MotionEvent ev) {
229228
return;
230229
}
231230

232-
EventDispatcher eventDispatcher =
233-
UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType());
231+
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(getCurrentReactContext());
234232
if (eventDispatcher != null) {
235233
mJSTouchDispatcher.onChildEndedNativeGesture(ev, eventDispatcher);
236234
if (mJSPointerDispatcher != null) {
@@ -411,8 +409,7 @@ protected void dispatchJSPointerEvent(MotionEvent event, boolean isCapture) {
411409
return;
412410
}
413411

414-
EventDispatcher eventDispatcher =
415-
UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType());
412+
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(getCurrentReactContext());
416413
if (eventDispatcher != null) {
417414
mJSPointerDispatcher.handleMotionEvent(event, eventDispatcher, isCapture);
418415
}
@@ -428,8 +425,7 @@ protected void dispatchJSTouchEvent(MotionEvent event) {
428425
return;
429426
}
430427

431-
EventDispatcher eventDispatcher =
432-
UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType());
428+
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(getCurrentReactContext());
433429
if (eventDispatcher != null) {
434430
mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher, getCurrentReactContext());
435431
}
@@ -451,8 +447,7 @@ protected void dispatchJSKeyEvent(KeyEvent ev) {
451447
}
452448
ReactContext context = getCurrentReactContext();
453449
if (context != null) {
454-
EventDispatcher eventDispatcher =
455-
UIManagerHelper.getEventDispatcher(context, getUIManagerType());
450+
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(context);
456451
int surfaceId = UIManagerHelper.getSurfaceId(context);
457452
if (eventDispatcher != null) {
458453
mJSKeyDispatcher.handleKeyEvent(ev, eventDispatcher, surfaceId);

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R
134134
logSoftException(
135135
TAG,
136136
IllegalArgumentException(
137-
"getJSModule(RCTEventEmitter) is not recommended in the new architecture and will stop working with interop disabled. Please use UIManagerHelper.getEventDispatcher or UIManagerHelper.getEventDispatcherForReactTag instead"
137+
"getJSModule(RCTEventEmitter) is not recommended in the new architecture and will stop working with interop disabled. Please use UIManagerHelper.getEventDispatcher instead"
138138
),
139139
)
140140
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,7 @@ public void onFocusChange(View view, boolean hasFocus) {
10391039
if (view.getContext() instanceof ThemedReactContext) {
10401040
ThemedReactContext themedReactContext = (ThemedReactContext) view.getContext();
10411041
@Nullable
1042-
EventDispatcher eventDispatcher =
1043-
UIManagerHelper.getEventDispatcherForReactTag(themedReactContext, view.getId());
1042+
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(themedReactContext);
10441043
if (eventDispatcher != null) {
10451044
if (hasFocus) {
10461045
eventDispatcher.dispatchEvent(new FocusEvent(surfaceId, view.getId()));

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.kt

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,56 +112,32 @@ public object UIManagerHelper {
112112
}
113113
}
114114

115-
/** @return the [EventDispatcher] that handles events for the reactTag received as a parameter. */
115+
/** @return the [EventDispatcher] that handles events for the given [ReactContext]. */
116116
@JvmStatic
117-
public fun getEventDispatcherForReactTag(context: ReactContext, reactTag: Int): EventDispatcher? {
118-
val eventDispatcher = getEventDispatcher(context, getUIManagerType(reactTag))
119-
if (eventDispatcher == null) {
120-
ReactSoftExceptionLogger.logSoftException(
121-
TAG,
122-
IllegalStateException("Cannot get EventDispatcher for reactTag $reactTag"),
123-
)
117+
public fun getEventDispatcher(context: ReactContext): EventDispatcher? {
118+
var localContext = context
119+
if (localContext is ThemedReactContext) {
120+
localContext = localContext.reactApplicationContext
124121
}
125-
return eventDispatcher
122+
return (localContext as EventDispatcherProvider).getEventDispatcher()
126123
}
127124

125+
/** @return the [EventDispatcher] that handles events for the reactTag received as a parameter. */
126+
@JvmStatic
127+
@Deprecated("reactTag is no longer needed", ReplaceWith("getEventDispatcher(context)"))
128+
public fun getEventDispatcherForReactTag(context: ReactContext, reactTag: Int): EventDispatcher? =
129+
getEventDispatcher(context)
130+
128131
/**
129132
* @return the [EventDispatcher] that handles events for the [UIManagerType] received as a
130133
* parameter.
131134
*/
132135
@JvmStatic
136+
@Deprecated("UIManagerType is no longer needed", ReplaceWith("getEventDispatcher(context)"))
133137
public fun getEventDispatcher(
134138
context: ReactContext,
135139
@UIManagerType uiManagerType: Int,
136-
): EventDispatcher? {
137-
// TODO T67518514 Clean this up once we migrate everything over to bridgeless mode
138-
var localContext = context
139-
if (localContext.isBridgeless()) {
140-
if (localContext is ThemedReactContext) {
141-
localContext = localContext.reactApplicationContext
142-
}
143-
return (localContext as EventDispatcherProvider).getEventDispatcher()
144-
}
145-
val uiManager = getUIManager(localContext, uiManagerType, false)
146-
if (uiManager == null) {
147-
ReactSoftExceptionLogger.logSoftException(
148-
TAG,
149-
ReactNoCrashSoftException("Unable to find UIManager for UIManagerType $uiManagerType"),
150-
)
151-
return null
152-
}
153-
val eventDispatcher = uiManager.eventDispatcher
154-
// Linter shows "Condition is always 'false'."
155-
// Keeping it for now as it was in the original Java code.
156-
@Suppress("SENSELESS_COMPARISON")
157-
if (eventDispatcher == null) {
158-
ReactSoftExceptionLogger.logSoftException(
159-
TAG,
160-
IllegalStateException("Cannot get EventDispatcher for UIManagerType $uiManagerType"),
161-
)
162-
}
163-
return eventDispatcher
164-
}
140+
): EventDispatcher? = getEventDispatcher(context)
165141

166142
/**
167143
* @return The [ReactContext] associated to the [View] received as a parameter.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public class ReactDrawerLayoutManager :
4646
reactContext: ThemedReactContext,
4747
view: ReactDrawerLayout,
4848
) {
49-
val eventDispatcher =
50-
UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id) ?: return
49+
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext) ?: return
5150
view.addDrawerListener(DrawerEventEmitter(view, eventDispatcher))
5251
}
5352

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ public class ReactImageView(
129129
if (!shouldNotify) {
130130
downloadListener = null
131131
} else {
132-
val eventDispatcher =
133-
UIManagerHelper.getEventDispatcherForReactTag((context as ReactContext), id)
134-
132+
val eventDispatcher = UIManagerHelper.getEventDispatcher((context as ReactContext))
135133
downloadListener =
136134
object : ReactImageDownloadListener<ImageInfo>() {
137135
override fun onProgressChange(loaded: Int, total: Int) {
@@ -378,8 +376,7 @@ public class ReactImageView(
378376
} catch (e: RuntimeException) {
379377
// Only provide updates if downloadListener is set (shouldNotify is true)
380378
if (downloadListener != null) {
381-
val eventDispatcher =
382-
UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
379+
val eventDispatcher = UIManagerHelper.getEventDispatcher(context as ReactContext)
383380
eventDispatcher?.dispatchEvent(
384381
createErrorEvent(UIManagerHelper.getSurfaceId(this), id, e)
385382
)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal class ReactModalHostManager :
9191
}
9292

9393
override fun addEventEmitters(reactContext: ThemedReactContext, view: ReactModalHostView) {
94-
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id)
94+
val dispatcher = UIManagerHelper.getEventDispatcher(reactContext)
9595
if (dispatcher != null) {
9696
view.onRequestCloseListener = OnRequestCloseListener {
9797
dispatcher.dispatchEvent(

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public object ReactScrollViewHelper {
133133
// if there's a crash initiated from JS and we tap on a ScrollView
134134
// around teardown of RN, this will cause a NPE. We can safely ignore
135135
// this since the crash is usually a red herring.
136-
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.id)
136+
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
137137
if (eventDispatcher != null) {
138138
eventDispatcher.dispatchEvent(
139139
ScrollEvent.obtain(

0 commit comments

Comments
 (0)