diff --git a/CHANGELOG.md b/CHANGELOG.md index ed243764..cf62d831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- Android: `onEvent` callback not being called on `PlayerView` - iOS: `onEvent` on iOS has incomplete payload information ## [0.14.1] (2023-11-16) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt index c2d166e7..0c2c23d7 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt @@ -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", @@ -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(EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING, ::emitEvent) + private val playerEventRelay = EventRelay( + EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING, + ::emitEventFromPlayer, + ) /** * Relays the provided set of events, emitted by the player view, together with the associated name @@ -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 emitEventFromPlayer(name: String, event: E) { + emitEvent(name, event) + emitEvent("event", event) + } } /**