Skip to content

Commit

Permalink
feat: add iOS parsing for new PlayerViewConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
strangesource committed Oct 18, 2023
1 parent 4e9cf65 commit 8b6d92a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
34 changes: 34 additions & 0 deletions ios/RCTConvert+BitmovinPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,38 @@ extension RCTConvert {
#endif
return pictureInPictureConfig
}

/**
Utility method to instantiate a `UiConfig` from a JS object.
- Parameter json: JS object
- Returns: The produced `UiConfig` object
*/
static func playerViewConfig(_ json: Any?) -> RNPlayerViewConfig? {
guard let json = json as? [String: Any?],
let uiConfigJson = json["uiConfig"] as? [String: Any?] else {
return nil
}

return RNPlayerViewConfig(
uiConfig: UiConfig(
playbackSpeedSelectionEnabled: uiConfigJson["playbackSpeedSelectionEnabled"] as? Bool ?? true
)
)
}
}
/**
* React native specific PlayerViewConfig.
*/
internal struct RNPlayerViewConfig {
/**
* The react native specific ui configuration.
*/
let uiConfig: UiConfig
}

/**
* React native specific UiConfig.
*/
internal struct UiConfig {
let playbackSpeedSelectionEnabled: Bool
}
1 change: 1 addition & 0 deletions ios/RNPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class RNPlayerView: UIView {
@objc var onCastWaitingForDevice: RCTBubblingEventBlock?
@objc var onPictureInPictureAvailabilityChanged: RCTBubblingEventBlock?
@objc var pictureInPictureConfig: [String: Any]?
@objc var config: [String: Any]?

/// The `PlayerView` subview.
var playerView: PlayerView? {
Expand Down
1 change: 1 addition & 0 deletions ios/RNPlayerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ @interface RCT_EXTERN_REMAP_MODULE(NativePlayerView, RNPlayerViewManager, RCTVie
RCT_EXPORT_VIEW_PROPERTY(onCastWaitingForDevice, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureAvailabilityChanged, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(pictureInPictureConfig, NSDictionary)
RCT_EXPORT_VIEW_PROPERTY(config, NSDictionary)

RCT_EXTERN_METHOD(attachPlayer:(nonnull NSNumber *)viewId playerId:(NSString *)playerId playerConfig:(nullable NSDictionary *)playerConfig)
RCT_EXTERN_METHOD(attachFullscreenBridge:(nonnull NSNumber *)viewId fullscreenBridgeId:(NSString *)fullscreenBridgeId)
Expand Down
16 changes: 11 additions & 5 deletions ios/RNPlayerViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ public class RNPlayerViewManager: RCTViewManager {
return
}
#if os(iOS)
if let customMessageHandlerBridgeId = self.customMessageHandlerBridgeId,
let customMessageHandlerBridge = self.bridge[CustomMessageHandlerModule.self]?
.retrieve(customMessageHandlerBridgeId),
player.config.styleConfig.userInterfaceType == .bitmovin {
if player.config.styleConfig.userInterfaceType == .bitmovin {
let bitmovinUserInterfaceConfig = player
.config
.styleConfig
.userInterfaceConfig as? BitmovinUserInterfaceConfig ?? BitmovinUserInterfaceConfig()
player.config.styleConfig.userInterfaceConfig = bitmovinUserInterfaceConfig
bitmovinUserInterfaceConfig.customMessageHandler = customMessageHandlerBridge.customMessageHandler
if let config = RCTConvert.playerViewConfig(view.config) {
bitmovinUserInterfaceConfig.playbackSpeedSelectionEnabled =
config.uiConfig.playbackSpeedSelectionEnabled
}

if let customMessageHandlerBridgeId = self.customMessageHandlerBridgeId,
let customMessageHandlerBridge =
self.bridge[CustomMessageHandlerModule.self]?.retrieve(customMessageHandlerBridgeId) {
bitmovinUserInterfaceConfig.customMessageHandler = customMessageHandlerBridge.customMessageHandler
}
}
#endif

Expand Down

0 comments on commit 8b6d92a

Please sign in to comment.