From d54a19a9789b799566da16a89e2cd8d8f1ad0ba7 Mon Sep 17 00:00:00 2001 From: MJ Studio Date: Thu, 11 Apr 2024 18:13:51 +0900 Subject: [PATCH] chore(Android): fix emit type parameters (#2087) ## Description Currently, on Android every event has one class, putted in generic - `ScreenAppearEvent`. This seems to be wrong, as every event should have their own class inside `Event` generic. This PR changes this by replacing `ScreenAppearEvent` to the appropriate event class. ## Changes - Replaced ScreenAppearEvent to appropriate event types inside generics. ## Checklist - [x] Ensured that CI passes --------- Co-authored-by: tboba --- .../src/main/java/com/swmansion/rnscreens/Screen.kt | 6 ++++-- .../swmansion/rnscreens/events/HeaderAttachedEvent.kt | 2 +- .../rnscreens/events/HeaderBackButtonClickedEvent.kt | 2 +- .../swmansion/rnscreens/events/HeaderDetachedEvent.kt | 2 +- .../rnscreens/events/HeaderHeightChangeEvent.kt | 10 +++++----- .../rnscreens/events/ScreenTransitionProgressEvent.kt | 2 +- .../swmansion/rnscreens/events/SearchBarBlurEvent.kt | 2 +- .../rnscreens/events/SearchBarChangeTextEvent.kt | 2 +- .../swmansion/rnscreens/events/SearchBarCloseEvent.kt | 2 +- .../swmansion/rnscreens/events/SearchBarFocusEvent.kt | 2 +- .../swmansion/rnscreens/events/SearchBarOpenEvent.kt | 2 +- .../events/SearchBarSearchButtonPressEvent.kt | 2 +- 12 files changed, 19 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/com/swmansion/rnscreens/Screen.kt b/android/src/main/java/com/swmansion/rnscreens/Screen.kt index 46cfad7767..b31e3788e1 100644 --- a/android/src/main/java/com/swmansion/rnscreens/Screen.kt +++ b/android/src/main/java/com/swmansion/rnscreens/Screen.kt @@ -253,8 +253,10 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) { } private fun notifyHeaderHeightChange(headerHeight: Double) { - UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id) - ?.dispatchEvent(HeaderHeightChangeEvent(id, headerHeight)) + val screenContext = context as ReactContext + val surfaceId = UIManagerHelper.getSurfaceId(screenContext) + UIManagerHelper.getEventDispatcherForReactTag(screenContext, id) + ?.dispatchEvent(HeaderHeightChangeEvent(surfaceId, id, headerHeight)) } enum class StackPresentation { diff --git a/android/src/main/java/com/swmansion/rnscreens/events/HeaderAttachedEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/HeaderAttachedEvent.kt index 30855b3484..777a95f406 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/HeaderAttachedEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/HeaderAttachedEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class HeaderAttachedEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class HeaderAttachedEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/HeaderBackButtonClickedEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/HeaderBackButtonClickedEvent.kt index 9a6b12246b..d7fa04f9ae 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/HeaderBackButtonClickedEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/HeaderBackButtonClickedEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class HeaderBackButtonClickedEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class HeaderBackButtonClickedEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/HeaderDetachedEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/HeaderDetachedEvent.kt index 143b4ca9ef..f4286e9c20 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/HeaderDetachedEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/HeaderDetachedEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class HeaderDetachedEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class HeaderDetachedEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/HeaderHeightChangeEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/HeaderHeightChangeEvent.kt index e69800b8a7..dfc1932b56 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/HeaderHeightChangeEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/HeaderHeightChangeEvent.kt @@ -1,23 +1,23 @@ package com.swmansion.rnscreens.events import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event import com.facebook.react.uimanager.events.RCTEventEmitter class HeaderHeightChangeEvent( + surfaceId: Int, viewId: Int, private val headerHeight: Double -) : Event(viewId) { +) : Event(surfaceId, viewId) { override fun getEventName() = EVENT_NAME // As the same header height could appear twice, use header height as a coalescing key. override fun getCoalescingKey(): Short = headerHeight.toInt().toShort() - override fun dispatch(rctEventEmitter: RCTEventEmitter) { - val map = Arguments.createMap() - map.putDouble("headerHeight", headerHeight) - rctEventEmitter.receiveEvent(viewTag, eventName, map) + override fun getEventData(): WritableMap? = Arguments.createMap().apply { + putDouble("headerHeight", headerHeight) } companion object { diff --git a/android/src/main/java/com/swmansion/rnscreens/events/ScreenTransitionProgressEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/ScreenTransitionProgressEvent.kt index 55d1ffe38e..f414595722 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/ScreenTransitionProgressEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/ScreenTransitionProgressEvent.kt @@ -11,7 +11,7 @@ class ScreenTransitionProgressEvent( private val isClosing: Boolean, private val isGoingForward: Boolean, private val coalescingKey: Short -) : Event(surfaceId, viewId) { +) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME override fun getCoalescingKey(): Short = coalescingKey diff --git a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarBlurEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarBlurEvent.kt index 92eaebd21b..dbe1424a99 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarBlurEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarBlurEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class SearchBarBlurEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class SearchBarBlurEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarChangeTextEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarChangeTextEvent.kt index b188b2bbcb..155c8bc12b 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarChangeTextEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarChangeTextEvent.kt @@ -8,7 +8,7 @@ class SearchBarChangeTextEvent( surfaceId: Int, viewId: Int, private val text: String?, -) : Event(surfaceId, viewId) { +) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarCloseEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarCloseEvent.kt index 07afdca429..9e0aa7318c 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarCloseEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarCloseEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class SearchBarCloseEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class SearchBarCloseEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarFocusEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarFocusEvent.kt index 241ec7c068..99ef941111 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarFocusEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarFocusEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class SearchBarFocusEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class SearchBarFocusEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarOpenEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarOpenEvent.kt index 13a712c0c1..10f2f478b7 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarOpenEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarOpenEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class SearchBarOpenEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { +class SearchBarOpenEvent(surfaceId: Int, viewId: Int) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced. diff --git a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarSearchButtonPressEvent.kt b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarSearchButtonPressEvent.kt index c1094f19cc..7ec2d096ea 100644 --- a/android/src/main/java/com/swmansion/rnscreens/events/SearchBarSearchButtonPressEvent.kt +++ b/android/src/main/java/com/swmansion/rnscreens/events/SearchBarSearchButtonPressEvent.kt @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -class SearchBarSearchButtonPressEvent(surfaceId: Int, viewId: Int, private val text: String?) : Event(surfaceId, viewId) { +class SearchBarSearchButtonPressEvent(surfaceId: Int, viewId: Int, private val text: String?) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME // All events for a given view can be coalesced.