Skip to content

Commit

Permalink
Merge branch 'development' into fix-onEvent-payload-on-iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandkakonyi authored Nov 24, 2023
2 parents 4bd085e + 9b447c9 commit b4fd7ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 b4fd7ac

Please sign in to comment.