Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/simplify fullscreen view reparenting #436

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions ios/THEOplayerRCTView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

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