Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ReactPopupMenuContainer(context: Context) : FrameLayout(context) {
}
popupMenu.setOnMenuItemClickListener { menuItem ->
val reactContext = context as ReactContext
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
if (eventDispatcher != null) {
val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
eventDispatcher.dispatchEvent(PopupMenuSelectionEvent(surfaceId, id, menuItem.order))
Expand All @@ -43,7 +43,7 @@ public class ReactPopupMenuContainer(context: Context) : FrameLayout(context) {
}
popupMenu.setOnDismissListener {
val reactContext = context as ReactContext
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
if (eventDispatcher != null) {
val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
eventDispatcher.dispatchEvent(PopupMenuDismissEvent(surfaceId, id))
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -4324,6 +4324,7 @@ public final class com/facebook/react/uimanager/UIManagerHelper {
public static final field PADDING_START_INDEX I
public static final field PADDING_TOP_INDEX I
public static final fun getDefaultTextInputPadding (Landroid/content/Context;)[F
public static final fun getEventDispatcher (Lcom/facebook/react/bridge/ReactContext;)Lcom/facebook/react/uimanager/events/EventDispatcher;
public static final fun getEventDispatcher (Lcom/facebook/react/bridge/ReactContext;I)Lcom/facebook/react/uimanager/events/EventDispatcher;
public static final fun getEventDispatcherForReactTag (Lcom/facebook/react/bridge/ReactContext;I)Lcom/facebook/react/uimanager/events/EventDispatcher;
public static final fun getReactContext (Landroid/view/View;)Lcom/facebook/react/bridge/ReactContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ public void onChildStartedNativeGesture(View childView, MotionEvent ev) {
return;
}

EventDispatcher eventDispatcher =
UIManagerHelper.getEventDispatcher(reactContext, getUIManagerType());
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext);
if (eventDispatcher != null) {
mJSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher, reactContext);
if (childView != null && mJSPointerDispatcher != null) {
Expand All @@ -229,8 +228,7 @@ public void onChildEndedNativeGesture(View childView, MotionEvent ev) {
return;
}

EventDispatcher eventDispatcher =
UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType());
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(getCurrentReactContext());
if (eventDispatcher != null) {
mJSTouchDispatcher.onChildEndedNativeGesture(ev, eventDispatcher);
if (mJSPointerDispatcher != null) {
Expand Down Expand Up @@ -411,8 +409,7 @@ protected void dispatchJSPointerEvent(MotionEvent event, boolean isCapture) {
return;
}

EventDispatcher eventDispatcher =
UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType());
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(getCurrentReactContext());
if (eventDispatcher != null) {
mJSPointerDispatcher.handleMotionEvent(event, eventDispatcher, isCapture);
}
Expand All @@ -428,8 +425,7 @@ protected void dispatchJSTouchEvent(MotionEvent event) {
return;
}

EventDispatcher eventDispatcher =
UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType());
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(getCurrentReactContext());
if (eventDispatcher != null) {
mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher, getCurrentReactContext());
}
Expand All @@ -451,8 +447,7 @@ protected void dispatchJSKeyEvent(KeyEvent ev) {
}
ReactContext context = getCurrentReactContext();
if (context != null) {
EventDispatcher eventDispatcher =
UIManagerHelper.getEventDispatcher(context, getUIManagerType());
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(context);
int surfaceId = UIManagerHelper.getSurfaceId(context);
if (eventDispatcher != null) {
mJSKeyDispatcher.handleKeyEvent(ev, eventDispatcher, surfaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R
logSoftException(
TAG,
IllegalArgumentException(
"getJSModule(RCTEventEmitter) is not recommended in the new architecture and will stop working with interop disabled. Please use UIManagerHelper.getEventDispatcher or UIManagerHelper.getEventDispatcherForReactTag instead"
"getJSModule(RCTEventEmitter) is not recommended in the new architecture and will stop working with interop disabled. Please use UIManagerHelper.getEventDispatcher instead"
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,7 @@ public void onFocusChange(View view, boolean hasFocus) {
if (view.getContext() instanceof ThemedReactContext) {
ThemedReactContext themedReactContext = (ThemedReactContext) view.getContext();
@Nullable
EventDispatcher eventDispatcher =
UIManagerHelper.getEventDispatcherForReactTag(themedReactContext, view.getId());
EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcher(themedReactContext);
if (eventDispatcher != null) {
if (hasFocus) {
eventDispatcher.dispatchEvent(new FocusEvent(surfaceId, view.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,56 +112,32 @@ public object UIManagerHelper {
}
}

/** @return the [EventDispatcher] that handles events for the reactTag received as a parameter. */
/** @return the [EventDispatcher] that handles events for the given [ReactContext]. */
@JvmStatic
public fun getEventDispatcherForReactTag(context: ReactContext, reactTag: Int): EventDispatcher? {
val eventDispatcher = getEventDispatcher(context, getUIManagerType(reactTag))
if (eventDispatcher == null) {
ReactSoftExceptionLogger.logSoftException(
TAG,
IllegalStateException("Cannot get EventDispatcher for reactTag $reactTag"),
)
public fun getEventDispatcher(context: ReactContext): EventDispatcher? {
var localContext = context
if (localContext is ThemedReactContext) {
localContext = localContext.reactApplicationContext
}
return eventDispatcher
return (localContext as EventDispatcherProvider).getEventDispatcher()
}

/** @return the [EventDispatcher] that handles events for the reactTag received as a parameter. */
@JvmStatic
@Deprecated("reactTag is no longer needed", ReplaceWith("getEventDispatcher(context)"))
public fun getEventDispatcherForReactTag(context: ReactContext, reactTag: Int): EventDispatcher? =
getEventDispatcher(context)

/**
* @return the [EventDispatcher] that handles events for the [UIManagerType] received as a
* parameter.
*/
@JvmStatic
@Deprecated("UIManagerType is no longer needed", ReplaceWith("getEventDispatcher(context)"))
public fun getEventDispatcher(
context: ReactContext,
@UIManagerType uiManagerType: Int,
): EventDispatcher? {
// TODO T67518514 Clean this up once we migrate everything over to bridgeless mode
var localContext = context
if (localContext.isBridgeless()) {
if (localContext is ThemedReactContext) {
localContext = localContext.reactApplicationContext
}
return (localContext as EventDispatcherProvider).getEventDispatcher()
}
val uiManager = getUIManager(localContext, uiManagerType, false)
if (uiManager == null) {
ReactSoftExceptionLogger.logSoftException(
TAG,
ReactNoCrashSoftException("Unable to find UIManager for UIManagerType $uiManagerType"),
)
return null
}
val eventDispatcher = uiManager.eventDispatcher
// Linter shows "Condition is always 'false'."
// Keeping it for now as it was in the original Java code.
@Suppress("SENSELESS_COMPARISON")
if (eventDispatcher == null) {
ReactSoftExceptionLogger.logSoftException(
TAG,
IllegalStateException("Cannot get EventDispatcher for UIManagerType $uiManagerType"),
)
}
return eventDispatcher
}
): EventDispatcher? = getEventDispatcher(context)

/**
* @return The [ReactContext] associated to the [View] received as a parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public class ReactDrawerLayoutManager :
reactContext: ThemedReactContext,
view: ReactDrawerLayout,
) {
val eventDispatcher =
UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id) ?: return
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext) ?: return
view.addDrawerListener(DrawerEventEmitter(view, eventDispatcher))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public class ReactImageView(
if (!shouldNotify) {
downloadListener = null
} else {
val eventDispatcher =
UIManagerHelper.getEventDispatcherForReactTag((context as ReactContext), id)

val eventDispatcher = UIManagerHelper.getEventDispatcher((context as ReactContext))
downloadListener =
object : ReactImageDownloadListener<ImageInfo>() {
override fun onProgressChange(loaded: Int, total: Int) {
Expand Down Expand Up @@ -378,8 +376,7 @@ public class ReactImageView(
} catch (e: RuntimeException) {
// Only provide updates if downloadListener is set (shouldNotify is true)
if (downloadListener != null) {
val eventDispatcher =
UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
val eventDispatcher = UIManagerHelper.getEventDispatcher(context as ReactContext)
eventDispatcher?.dispatchEvent(
createErrorEvent(UIManagerHelper.getSurfaceId(this), id, e)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal class ReactModalHostManager :
}

override fun addEventEmitters(reactContext: ThemedReactContext, view: ReactModalHostView) {
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id)
val dispatcher = UIManagerHelper.getEventDispatcher(reactContext)
if (dispatcher != null) {
view.onRequestCloseListener = OnRequestCloseListener {
dispatcher.dispatchEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public object ReactScrollViewHelper {
// if there's a crash initiated from JS and we tap on a ScrollView
// around teardown of RN, this will cause a NPE. We can safely ignore
// this since the crash is usually a red herring.
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.id)
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
if (eventDispatcher != null) {
eventDispatcher.dispatchEvent(
ScrollEvent.obtain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal open class SwipeRefreshLayoutManager :

override fun addEventEmitters(reactContext: ThemedReactContext, view: ReactSwipeRefreshLayout) {
view.setOnRefreshListener {
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id)
val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
eventDispatcher?.dispatchEvent(RefreshEvent(UIManagerHelper.getSurfaceId(view), view.id))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ internal class ReactSwitchManager :
CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
val reactContext = buttonView.context as ReactContext
val reactTag = buttonView.id
UIManagerHelper.getEventDispatcherForReactTag(reactContext, reactTag)
UIManagerHelper.getEventDispatcher(reactContext)
?.dispatchEvent(
ReactSwitchEvent(UIManagerHelper.getSurfaceId(reactContext), reactTag, isChecked)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class ReactClickableSpan(val reactTag: Int) : ClickableSpan(), ReactSpa

override fun onClick(view: View) {
val context = view.context as ReactContext
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, reactTag)
val eventDispatcher = UIManagerHelper.getEventDispatcher(context)
eventDispatcher?.dispatchEvent(
ViewGroupClickEvent(UIManagerHelper.getSurfaceId(context), reactTag)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class ReactLinkSpan(val fragmentIndex: Int) : ClickableSpan(), ReactSpa
else -> null
} ?: return
val reactTag = preparedLayout.reactTags[fragmentIndex]
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, reactTag)
val eventDispatcher = UIManagerHelper.getEventDispatcher(context)
eventDispatcher?.dispatchEvent(
ViewGroupClickEvent(UIManagerHelper.getSurfaceId(context), reactTag)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ReactTextContentSizeWatcher(private val editText: ReactEditText)

init {
val reactContext = UIManagerHelper.getReactContext(editText)
eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)
eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
surfaceId = UIManagerHelper.getSurfaceId(reactContext)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,6 @@ public open class ReactTextInputManager public constructor() :
private fun getEventDispatcher(
reactContext: ReactContext,
editText: ReactEditText,
): EventDispatcher? = UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)
): EventDispatcher? = UIManagerHelper.getEventDispatcher(reactContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ internal class ReactTextInputTextWatcher(
reactContext: ReactContext,
private val editText: ReactEditText,
) : TextWatcher {
private val eventDispatcher: EventDispatcher? =
UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)
private val eventDispatcher: EventDispatcher? = UIManagerHelper.getEventDispatcher(reactContext)
private val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
private var previousText: String? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ReactTextScrollWatcher(private val editText: ReactEditText) : Scr

init {
val reactContext = UIManagerHelper.getReactContext(editText)
eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)
eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
surfaceId = UIManagerHelper.getSurfaceId(reactContext)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ReactTextSelectionWatcher(private val editText: ReactEditText) :

init {
val reactContext = UIManagerHelper.getReactContext(editText)
eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)
eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext)
surfaceId = UIManagerHelper.getSurfaceId(reactContext)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
public open fun setFocusable(view: ReactViewGroup, focusable: Boolean) {
if (focusable) {
view.setOnClickListener {
val eventDispatcher =
UIManagerHelper.getEventDispatcherForReactTag((view.context as ReactContext), view.id)
val eventDispatcher = UIManagerHelper.getEventDispatcher(view.context as ReactContext)
eventDispatcher?.dispatchEvent(
ViewGroupClickEvent(UIManagerHelper.getSurfaceId(view.context), view.id)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ReactVirtualViewManager :
reactContext: ThemedReactContext,
view: ReactVirtualView,
) {
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id) ?: return
val dispatcher = UIManagerHelper.getEventDispatcher(reactContext) ?: return
view.modeChangeEmitter =
VirtualViewEventEmitter(view.id, UIManagerHelper.getSurfaceId(reactContext), dispatcher)
}
Expand Down
Loading
Loading