diff --git a/CHANGELOG.md b/CHANGELOG.md index 94d1db827..984b111c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The `MediaPlaybackService` on Android is never restarted if a MediaButton event is received after the app was closed. - Added a consumer R8 config file on Android, telling R8 not to throw errors or warnings because of classes that are expected to be missing. +- Simplified the viewController reparenting mechanism on iOS that is applied when changing the `presentationMode` to/from fullscreen. ## [8.7.0] - 24-11-05 diff --git a/ios/THEOplayerRCTView.swift b/ios/THEOplayerRCTView.swift index 7703267fe..4822d1eed 100644 --- a/ios/THEOplayerRCTView.swift +++ b/ios/THEOplayerRCTView.swift @@ -9,6 +9,7 @@ public class THEOplayerRCTView: UIView { public private(set) var player: THEOplayer? public private(set) var mainEventHandler: THEOplayerRCTMainEventHandler public private(set) var broadcastEventHandler: THEOplayerRCTBroadcastEventHandler + let theoPlayerViewController = UIViewController() var textTrackEventHandler: THEOplayerRCTTextTrackEventHandler var mediaTrackEventHandler: THEOplayerRCTMediaTrackEventHandler var metadataTrackEventHandler: THEOplayerRCTSideloadedMetadataTrackEventHandler @@ -76,6 +77,14 @@ public class THEOplayerRCTView: UIView { if let player = self.player { player.frame = self.frame player.autoresizingMask = [.flexibleBottomMargin, .flexibleHeight, .flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleWidth] + + // wrap theoPlayerViewController around the view + if theoPlayerViewController.parent == nil, + let parentViewController = self.findViewController() { + parentViewController.addChild(self.theoPlayerViewController) + self.theoPlayerViewController.didMove(toParent: parentViewController) + self.theoPlayerViewController.view = self + } } } diff --git a/ios/presentationMode/THEOplayerRCTPresentationModeManager.swift b/ios/presentationMode/THEOplayerRCTPresentationModeManager.swift index 7b2cd94d9..4f6bbecae 100644 --- a/ios/presentationMode/THEOplayerRCTPresentationModeManager.swift +++ b/ios/presentationMode/THEOplayerRCTPresentationModeManager.swift @@ -14,7 +14,6 @@ public class THEOplayerRCTPresentationModeManager { private var containerView: UIView? // view containing the playerView and it's siblings (e.g. UI) private var inlineParentView: UIView? // target view for inline representation - private var movingChildVCs: [UIViewController] = [] // list of playerView's child VCs that need to be reparented while moving the playerView // MARK: Events var onNativePresentationModeChange: RCTDirectEventBlock? @@ -39,35 +38,21 @@ public class THEOplayerRCTPresentationModeManager { // MARK: - logic - private func storeMovingVCs(for view: UIView) { - if let viewController = view.findViewController() { - viewController.children.forEach { childVC in - self.movingChildVCs.append(childVC) - } - } - } - - private func clearMovingVCs() { - self.movingChildVCs = [] - } - - private func moveView(_ movingView: UIView, to targetView: UIView, with movingViewControllers: [UIViewController]) { - // detach the moving viewControllers from their parent - movingViewControllers.forEach { movedVC in - movedVC.removeFromParent() - } + private func moveView(_ movingView: UIView, to targetView: UIView) { + guard let theoPlayerViewController = (self.view as? THEOplayerRCTView)?.theoPlayerViewController else { return } + + // detach the viewController from its parent + theoPlayerViewController.removeFromParent() // move the actual view movingView.removeFromSuperview() targetView.addSubview(movingView) targetView.bringSubviewToFront(movingView) - // attach the moving viewControllers to their new parent + // attach the viewController to its new parent if let targetViewController = targetView.findViewController() { - movingViewControllers.forEach { movedVC in - targetViewController.addChild(movedVC) - movedVC.didMove(toParent: targetViewController) - } + targetViewController.addChild(theoPlayerViewController) + theoPlayerViewController.didMove(toParent: targetViewController) } } @@ -77,8 +62,7 @@ public class THEOplayerRCTPresentationModeManager { if let containerView = self.containerView, let fullscreenParentView = self.view?.findParentViewOfType(RCTRootContentView.self) { - self.storeMovingVCs(for: containerView) - self.moveView(containerView, to: fullscreenParentView, with: self.movingChildVCs) + self.moveView(containerView, to: fullscreenParentView) } self.rnInlineMode = .fullscreen } @@ -86,8 +70,7 @@ public class THEOplayerRCTPresentationModeManager { private func exitFullscreen() { if let containerView = self.containerView, let inlineParentView = self.inlineParentView { - self.moveView(containerView, to: inlineParentView, with: self.movingChildVCs) - self.clearMovingVCs() + self.moveView(containerView, to: inlineParentView) } self.rnInlineMode = .inline }