Fix iPad rotation related issue when in PiP

This commit is contained in:
Daniel Ornelas 2018-03-22 11:22:33 -05:00 committed by Lyubo Marinov
parent 15e1633d86
commit 7822155e5e
5 changed files with 45 additions and 16 deletions

View File

@ -32,8 +32,8 @@ class ViewController: UIViewController {
@IBAction func openJitsiMeet(sender: Any?) { @IBAction func openJitsiMeet(sender: Any?) {
let jitsiMeetCoordinator = JitsiMeetPresentationCoordinator() let jitsiMeetCoordinator = JitsiMeetPresentationCoordinator()
self.jitsiMeetCoordinator = jitsiMeetCoordinator self.jitsiMeetCoordinator = jitsiMeetCoordinator
jitsiMeetCoordinator.jitsiMeetView().welcomePageEnabled = true jitsiMeetCoordinator.jitsiMeetView.welcomePageEnabled = true
jitsiMeetCoordinator.jitsiMeetView().load(nil) jitsiMeetCoordinator.jitsiMeetView.load(nil)
jitsiMeetCoordinator.show() jitsiMeetCoordinator.show()
} }
} }

View File

@ -20,8 +20,20 @@ import Foundation
/// an external window that can be resized and dragged with custom PiP mode /// an external window that can be resized and dragged with custom PiP mode
open class JitsiMeetPresentationCoordinator: NSObject { open class JitsiMeetPresentationCoordinator: NSObject {
fileprivate let meetViewController: JitsiMeetViewController public let meetViewController: JitsiMeetViewController
fileprivate let meetWindow: PiPWindow public let meetWindow: PiPWindow
public var isInPiP: Bool {
get {
return meetWindow.isInPiP
}
}
public var jitsiMeetView: JitsiMeetView {
get {
return meetViewController.jitsiMeetView
}
}
public init(meetViewController: JitsiMeetViewController? = nil, public init(meetViewController: JitsiMeetViewController? = nil,
meetWindow: PiPWindow? = nil) { meetWindow: PiPWindow? = nil) {
@ -34,14 +46,12 @@ open class JitsiMeetPresentationCoordinator: NSObject {
configureMeetViewController() configureMeetViewController()
} }
public func jitsiMeetView() -> JitsiMeetView { /// Show window with jitsi meet and perform a completion closure
return meetViewController.jitsiMeetView
}
open func show(completion: CompletionAction? = nil) { open func show(completion: CompletionAction? = nil) {
meetWindow.show(completion: completion) meetWindow.show(completion: completion)
} }
/// Hide window with jitsi meet and perform a completion closure
open func hide(completion: CompletionAction? = nil) { open func hide(completion: CompletionAction? = nil) {
meetWindow.hide(completion: completion) meetWindow.hide(completion: completion)
} }
@ -77,7 +87,7 @@ extension JitsiMeetPresentationCoordinator: JitsiMeetViewControllerDelegate {
switch to { switch to {
case .enterPictureInPicture: case .enterPictureInPicture:
meetWindow.enterPictureInPicture() meetWindow.enterPictureInPicture()
case .traitChange: case .sizeChange:
// resize to full screen if rotation happens // resize to full screen if rotation happens
if meetWindow.isInPiP { if meetWindow.isInPiP {
meetWindow.exitPictureInPicture() meetWindow.exitPictureInPicture()

View File

@ -19,8 +19,8 @@ public enum JitsiMeetPresentationUpdate {
/// The conference wants to enter Picture-in-Picture /// The conference wants to enter Picture-in-Picture
case enterPictureInPicture case enterPictureInPicture
/// A system traitCollectionChange (usually screen rotation) /// A screen size change (usually screen rotation)
case traitChange case sizeChange
} }
public protocol JitsiMeetViewControllerDelegate: class { public protocol JitsiMeetViewControllerDelegate: class {
@ -59,9 +59,10 @@ open class JitsiMeetViewController: UIViewController {
jitsiMeetView.delegate = self jitsiMeetView.delegate = self
} }
open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
delegate?.performPresentationUpdate(to: .traitChange) super.viewWillTransition(to: size, with: coordinator)
delegate?.performPresentationUpdate(to: .sizeChange)
} }
} }

View File

@ -32,7 +32,17 @@ open class PiPWindow: UIWindow {
} }
/// The size ratio for root view controller view when in PiP mode /// The size ratio for root view controller view when in PiP mode
public var pipSizeRatio: CGFloat = 0.333 public var pipSizeRatio: CGFloat = {
let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
switch (deviceIdiom) {
case .pad:
return 0.25
case .phone:
return 0.33
default:
return 0.25
}
}()
/// The PiP state of this contents of the window /// The PiP state of this contents of the window
private(set) var isInPiP: Bool = false private(set) var isInPiP: Bool = false

View File

@ -7,8 +7,16 @@ import type { Dispatch } from 'redux';
/** /**
* Size threshold for determining if we are in reduced UI mode or not. * Size threshold for determining if we are in reduced UI mode or not.
*
* FIXME The logic to base {@code reducedUI} on a hardcoded width or height is
* very brittle because it's completely disconnected from the UI which wants to
* be rendered and, naturally, it broke on iPad where even the secondary Toolbar
* didn't fit in the height. We do need to measure the actual UI at runtime and
* determine whether and how to render it. I'm bumping from 240 to 300 because I
* don't have the time now to refactor {@code ReducedUIDetector} or rip it out
* completely.
*/ */
const REDUCED_UI_THRESHOLD = 240; const REDUCED_UI_THRESHOLD = 300;
/** /**
* Sets the aspect ratio of the app's user interface based on specific width and * Sets the aspect ratio of the app's user interface based on specific width and