Skip to content

Commit

Permalink
Merge pull request #327 from bitmovin/fix-onEvent-support-on-android
Browse files Browse the repository at this point in the history
Fix `onEvent` never triggered on `PlayerView` on Android
  • Loading branch information
rolandkakonyi authored Nov 24, 2023
2 parents 9764276 + 30b29fb commit 9b447c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

- Android: `onEvent` callback not being called on `PlayerView`

## [0.14.1] (2023-11-16)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
import kotlin.reflect.KClass

private val EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING = mapOf(
PlayerEvent::class to "event",
PlayerEvent.Error::class to "playerError",
PlayerEvent.Warning::class to "playerWarning",
PlayerEvent.Destroy::class to "destroy",
Expand Down Expand Up @@ -139,7 +138,10 @@ class RNPlayerView(
* Relays the provided set of events, emitted by the player, together with the associated name
* to the `eventOutput` callback.
*/
private val playerEventRelay = EventRelay<Player, Event>(EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING, ::emitEvent)
private val playerEventRelay = EventRelay<Player, Event>(
EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING,
::emitEventFromPlayer,
)

/**
* Relays the provided set of events, emitted by the player view, together with the associated name
Expand Down Expand Up @@ -318,6 +320,17 @@ class RNPlayerView(
.getJSModule(RCTEventEmitter::class.java)
.receiveEvent(id, name, payload)
}

/**
* Emits a bubbling event from the player with payload to js
* and emits it for "event" to support `onEvent` prop.
* @param name Native event name.
* @param event Optional js object to be sent as payload.
*/
private inline fun <reified E : Event> emitEventFromPlayer(name: String, event: E) {
emitEvent(name, event)
emitEvent("event", event)
}
}

/**
Expand Down

0 comments on commit 9b447c9

Please sign in to comment.