Skip to content

Commit

Permalink
Use the wrapping theoPlayerViewController to reparent all underlying …
Browse files Browse the repository at this point in the history
…viewcontrollers
  • Loading branch information
wvanhaevre authored and tvanlaerhoven committed Nov 14, 2024
1 parent a752eb8 commit 09a478f
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions ios/presentationMode/THEOplayerRCTPresentationModeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)
}
}

Expand All @@ -77,17 +62,15 @@ 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
}

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
}
Expand Down

0 comments on commit 09a478f

Please sign in to comment.