From 8b6d92a648fee738ad3089df2e835621c7a59d94 Mon Sep 17 00:00:00 2001 From: Lukas Knoch-Girstmair Date: Wed, 18 Oct 2023 14:26:22 +0200 Subject: [PATCH] feat: add iOS parsing for new PlayerViewConfig --- ios/RCTConvert+BitmovinPlayer.swift | 34 +++++++++++++++++++++++++++++ ios/RNPlayerView.swift | 1 + ios/RNPlayerViewManager.m | 1 + ios/RNPlayerViewManager.swift | 16 +++++++++----- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/ios/RCTConvert+BitmovinPlayer.swift b/ios/RCTConvert+BitmovinPlayer.swift index 081e566d..64c44c54 100644 --- a/ios/RCTConvert+BitmovinPlayer.swift +++ b/ios/RCTConvert+BitmovinPlayer.swift @@ -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 } diff --git a/ios/RNPlayerView.swift b/ios/RNPlayerView.swift index d67daccd..b196614d 100644 --- a/ios/RNPlayerView.swift +++ b/ios/RNPlayerView.swift @@ -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? { diff --git a/ios/RNPlayerViewManager.m b/ios/RNPlayerViewManager.m index 1ef54f15..64e542e8 100644 --- a/ios/RNPlayerViewManager.m +++ b/ios/RNPlayerViewManager.m @@ -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) diff --git a/ios/RNPlayerViewManager.swift b/ios/RNPlayerViewManager.swift index ad9e74a6..7f5428b0 100644 --- a/ios/RNPlayerViewManager.swift +++ b/ios/RNPlayerViewManager.swift @@ -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