Skip to content

Commit

Permalink
chore(Android): fix emit type parameters (#2087)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
mym0404 and tboba authored Apr 11, 2024
1 parent 03dad84 commit d54a19a
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 17 deletions.
6 changes: 4 additions & 2 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class HeaderAttachedEvent(surfaceId: Int, viewId: Int) : Event<HeaderAttachedEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class HeaderBackButtonClickedEvent(surfaceId: Int, viewId: Int) : Event<HeaderBackButtonClickedEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class HeaderDetachedEvent(surfaceId: Int, viewId: Int) : Event<HeaderDetachedEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HeaderHeightChangeEvent>(viewId) {
) : Event<HeaderHeightChangeEvent>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ScreenTransitionProgressEvent(
private val isClosing: Boolean,
private val isGoingForward: Boolean,
private val coalescingKey: Short
) : Event<ScreenAppearEvent?>(surfaceId, viewId) {
) : Event<ScreenTransitionProgressEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

override fun getCoalescingKey(): Short = coalescingKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class SearchBarBlurEvent(surfaceId: Int, viewId: Int) : Event<SearchBarBlurEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SearchBarChangeTextEvent(
surfaceId: Int,
viewId: Int,
private val text: String?,
) : Event<ScreenAppearEvent>(surfaceId, viewId) {
) : Event<SearchBarChangeTextEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class SearchBarCloseEvent(surfaceId: Int, viewId: Int) : Event<SearchBarCloseEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class SearchBarFocusEvent(surfaceId: Int, viewId: Int) : Event<SearchBarFocusEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class SearchBarOpenEvent(surfaceId: Int, viewId: Int) : Event<SearchBarOpenEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScreenAppearEvent>(surfaceId, viewId) {
class SearchBarSearchButtonPressEvent(surfaceId: Int, viewId: Int, private val text: String?) : Event<SearchBarSearchButtonPressEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

// All events for a given view can be coalesced.
Expand Down

0 comments on commit d54a19a

Please sign in to comment.