Skip to content

Commit

Permalink
Undo breaking change on UIManager eventDispatcher accessor (#47088)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #47088

Whe migrating this interface to Kotlin we've subtly introduced a breaking change which is causing a lot of breakages in the ecosystem.

This is forcing users to do:
```
// Before
reactContext.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
// After
reactContext.getNativeModule(UIManagerModule::class.java)!!.getEventDispatcher()
```

This reverts this breaking change.

Plus the method had a generic parameters which was completely unnecessary so I'm removing it.

Changelog:
[Android] [Fixed] - Undo breaking change on UIManager eventDispatcher accessor

Reviewed By: cipolleschi

Differential Revision: D64533594

fbshipit-source-id: c4f9a36993a22839fae90fb239f883305422ecec
  • Loading branch information
cortinico authored and facebook-github-bot committed Oct 18, 2024
1 parent 5c6edc6 commit dc1a498
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void initializeEventListenerForUIManagerType(@UIManagerType final int uiM

UIManager uiManager = UIManagerHelper.getUIManager(mReactApplicationContext, uiManagerType);
if (uiManager != null) {
uiManager.<EventDispatcher>getEventDispatcher().addListener(this);
EventDispatcher eventDispatcher = (EventDispatcher) uiManager.getEventDispatcher();
eventDispatcher.addListener(this);
if (uiManagerType == UIManagerType.FABRIC) {
mEventListenerInitializedForFabric = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public interface UIManager : PerformanceCounter {
public fun dispatchCommand(reactTag: Int, commandId: String, commandArgs: ReadableArray?)

/** @return the [EventDispatcher] object that is used by this class. */
public fun <T> getEventDispatcher(): T
public val eventDispatcher: Any?

/**
* Used by native animated module to bypass the process of updating the values through the shadow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,6 @@ public void onHostResume() {

@Override
@NonNull
@SuppressWarnings("unchecked")
public EventDispatcher getEventDispatcher() {
return mEventDispatcher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,20 +577,19 @@ public boolean performAccessibilityAction(View host, int action, Bundle args) {
UIManager uiManager =
UIManagerHelper.getUIManager(reactContext, ViewUtil.getUIManagerType(reactTag));
if (uiManager != null) {
uiManager
.<EventDispatcher>getEventDispatcher()
.dispatchEvent(
new Event(surfaceId, reactTag) {
@Override
public String getEventName() {
return TOP_ACCESSIBILITY_ACTION_EVENT;
}

@Override
protected WritableMap getEventData() {
return event;
}
});
EventDispatcher eventDispatcher = (EventDispatcher) uiManager.getEventDispatcher();
eventDispatcher.dispatchEvent(
new Event(surfaceId, reactTag) {
@Override
public String getEventName() {
return TOP_ACCESSIBILITY_ACTION_EVENT;
}

@Override
protected WritableMap getEventData() {
return event;
}
});
}
} else {
ReactSoftExceptionLogger.logSoftException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RootViewTest {
val eventEmitterModuleMock = mock(RCTEventEmitter::class.java)
whenever(catalystInstanceMock.getNativeModule(UIManagerModule::class.java))
.thenReturn(uiManager)
whenever(uiManager.getEventDispatcher()).thenReturn(eventDispatcher)
whenever(uiManager.eventDispatcher).thenReturn(eventDispatcher)

// RootView IDs is React Native follow the 11, 21, 31, ... progression.
val rootViewId = 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class NativeAnimatedNodeTraversalTest {

uiManagerMock = mock(UIManagerModule::class.java)
eventDispatcherMock = mock(EventDispatcher::class.java)
whenever(uiManagerMock.getEventDispatcher()).thenAnswer { eventDispatcherMock }
whenever(uiManagerMock.eventDispatcher).thenAnswer { eventDispatcherMock }
whenever(uiManagerMock.constants).thenAnswer {
mapOf("customDirectEventTypes" to emptyMap<Any, Any>())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class TouchEventDispatchTest {
spy(FabricUIManager(reactContext, viewManagerRegistry, batchEventDispatchedListener))
uiManager.initialize()

eventDispatcher = uiManager.getEventDispatcher()
eventDispatcher = uiManager.eventDispatcher

// Ignore scheduled choreographer work
val reactChoreographerMock = mock(ReactChoreographer::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ class FakeUIManager : UIManager, UIBlockViewResolver {
error("Not yet implemented")
}

override fun <T : Any?> getEventDispatcher(): T {
error("Not yet implemented")
}
override val eventDispatcher: Any?
get() = TODO("Not yet implemented")

override fun synchronouslyUpdateViewOnUIThread(reactTag: Int, props: ReadableMap?) {
error("Not yet implemented")
Expand Down

0 comments on commit dc1a498

Please sign in to comment.