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

Adding vertical and horizontal notch support for X's iPhones #204

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions MobilePlayer/MobilePlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ open class MobilePlayerViewController: MPMoviePlayerViewController {
overlay: overlayViewController))
} else if overlayViewController.parent == nil {
overlayViewController.delegate = self
addChild(overlayViewController)
addChildViewController(overlayViewController)
overlayViewController.view.clipsToBounds = true
overlayViewController.view.frame = controlsView.overlayContainerView.bounds
controlsView.overlayContainerView.addSubview(overlayViewController.view)
overlayViewController.didMove(toParent: self)
overlayViewController.didMove(toParentViewController: self)
}
}

Expand All @@ -474,7 +474,7 @@ open class MobilePlayerViewController: MPMoviePlayerViewController {
timedOverlayInfo.overlay.dismiss()
}
timedOverlays.removeAll()
for childViewController in children {
for childViewController in childViewControllers {
if childViewController is WatermarkViewController { continue }
(childViewController as? MobilePlayerOverlayViewController)?.dismiss()
}
Expand Down Expand Up @@ -615,9 +615,9 @@ open class MobilePlayerViewController: MPMoviePlayerViewController {
extension MobilePlayerViewController: MobilePlayerOverlayViewControllerDelegate {

func dismiss(mobilePlayerOverlayViewController overlayViewController: MobilePlayerOverlayViewController) {
overlayViewController.willMove(toParent: nil)
overlayViewController.willMove(toParentViewController: nil)
overlayViewController.view.removeFromSuperview()
overlayViewController.removeFromParent()
overlayViewController.removeFromParentViewController()
if overlayViewController == prerollViewController {
play()
}
Expand Down
45 changes: 29 additions & 16 deletions MobilePlayer/Views/MobilePlayerControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import MediaPlayer
final class MobilePlayerControlsView: UIView {
let config: MobilePlayerConfig
let previewImageView = UIImageView(frame: .zero)
let activityIndicatorView = UIActivityIndicatorView(style: .white)
let activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .white)
let overlayContainerView = UIView(frame: .zero)
let topBar: Bar
let bottomBar: Bar
Expand Down Expand Up @@ -58,32 +58,45 @@ final class MobilePlayerControlsView: UIView {

override func layoutSubviews() {
let size = bounds.size

let iPhoneX = UIDevice().userInterfaceIdiom == .phone && (UIScreen.main.nativeBounds.height == 2436 || UIScreen.main.nativeBounds.height == 1792 || UIScreen.main.nativeBounds.height == 2688)
let landscape = UIDevice.current.orientation.isLandscape
var topSafeAreaHeight: CGFloat = 0.0
var bottomSafeAreaHeight: CGFloat = 0.0

if #available(iOS 11.0, *) {
let window = UIApplication.shared.windows[0]
let safeFrame = window.safeAreaLayoutGuide.layoutFrame
topSafeAreaHeight = safeFrame.minY
bottomSafeAreaHeight = window.frame.maxY - safeFrame.maxY
}

previewImageView.frame = bounds
activityIndicatorView.sizeToFit()
activityIndicatorView.frame.origin = CGPoint(
x: (size.width - activityIndicatorView.frame.size.width) / 2,
y: (size.height - activityIndicatorView.frame.size.height) / 2)
x: (size.width - activityIndicatorView.frame.size.width) / 2,
y: (size.height - activityIndicatorView.frame.size.height) / 2)
topBar.sizeToFit()
topBar.frame = CGRect(
x: 0,
y: controlsHidden ? -topBar.frame.size.height : 0,
width: size.width,
height: topBar.frame.size.height)
x: (iPhoneX && landscape) ? 44 : 0,
y: controlsHidden ? -topBar.frame.size.height : topSafeAreaHeight,
width: size.width - ((iPhoneX && landscape) ? 88 : 0),
height: topBar.frame.size.height)
topBar.alpha = controlsHidden ? 0 : 1
bottomBar.sizeToFit()
bottomBar.frame = CGRect(
x: 0,
y: size.height - (controlsHidden ? 0 : bottomBar.frame.size.height),
width: size.width,
height: bottomBar.frame.size.height)
x: (iPhoneX && landscape) ? 44 : 0,
y: size.height - (controlsHidden ? 0 : bottomBar.frame.size.height + bottomSafeAreaHeight),
width: size.width - ((iPhoneX && landscape) ? 88 : 0),
height: bottomBar.frame.size.height)
bottomBar.alpha = controlsHidden ? 0 : 1
overlayContainerView.frame = CGRect(
x: 0,
y: controlsHidden ? 0 : topBar.frame.size.height,
width: size.width,
height: size.height - (controlsHidden ? 0 : (topBar.frame.size.height + bottomBar.frame.size.height)))
x: 0,
y: controlsHidden ? 0 : topBar.frame.size.height,
width: size.width,
height: size.height - (controlsHidden ? 0 : (topBar.frame.size.height + bottomBar.frame.size.height)))
for overlay in overlayContainerView.subviews {
overlay.frame = overlayContainerView.bounds
overlay.frame = overlayContainerView.bounds
}
super.layoutSubviews()
}
Expand Down