Skip to content

Commit

Permalink
Full Screen changes (#333)
Browse files Browse the repository at this point in the history
* full screen for various views after login
  • Loading branch information
ShresthPratapSingh authored Jul 30, 2020
1 parent a24fb30 commit 9f7769a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 44 deletions.
1 change: 0 additions & 1 deletion AmahiAnywhere/AmahiAnywhere/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

populateRegistrationDomain()

UIViewController.setPresentationStyle_fullScreen()

useCastContainerViewController = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ extension FilesViewController: FilesView {
let videoPlayerVc = self.viewController(viewControllerClass: VideoPlayerViewController.self,
from: StoryBoardIdentifiers.videoPlayer)
videoPlayerVc.mediaURL = url
videoPlayerVc.modalPresentationStyle = .fullScreen
self.present(videoPlayerVc)

}
Expand Down Expand Up @@ -188,12 +189,7 @@ extension FilesViewController: FilesView {
AudioPlayerDataModel.shared.queuedItems = Array(items.suffix(from: currentIndex))
AudioPlayerDataModel.shared.itemURLs = Array(URLs.suffix(from: currentIndex))
AudioPlayerDataModel.shared.setupQueueMetadata()
if #available(iOS 13.0, *) {
audioPlayerVc.isModalInPresentation = true
}
if UIDevice().userInterfaceIdiom == .pad{
audioPlayerVc.modalPresentationStyle = .fullScreen
}
audioPlayerVc.modalPresentationStyle = .fullScreen
self.present(audioPlayerVc)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,41 +144,18 @@ class LoginViewController: BaseUIViewController {

}

extension UIViewController {

@objc private func swizzled_presentstyle(_ viewControllerToPresent: UIViewController, animated: Bool, completion: (() -> Void)?) {

if #available(iOS 13.0, *) {
if viewControllerToPresent.modalPresentationStyle == .automatic || viewControllerToPresent.modalPresentationStyle == .pageSheet {
viewControllerToPresent.modalPresentationStyle = .fullScreen
}
}

self.swizzled_presentstyle(viewControllerToPresent, animated: animated, completion: completion)
}

static func setPresentationStyle_fullScreen() {

let instance: UIViewController = UIViewController()
let aClass: AnyClass! = object_getClass(instance)

let originalSelector = #selector(UIViewController.present(_:animated:completion:))
let swizzledSelector = #selector(UIViewController.swizzled_presentstyle(_:animated:completion:))

let originalMethod = class_getInstanceMethod(aClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector)
if let originalMethod = originalMethod, let swizzledMethod = swizzledMethod {
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
}

// Mark - Login view implementations
extension LoginViewController: LoginView {

func showHome() {
let serverVc = self.instantiateViewController (withIdentifier: "RootVC", from: StoryBoardIdentifiers.main)
self.present(serverVc, animated: true, completion: nil)
if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let currentWindow = appDelegate.window{
UIView.transition(with: currentWindow, duration: 0.3, options: .transitionFlipFromRight, animations: {
//removing strong references from login VC to let ARC automatically delete it from memmory
currentWindow.rootViewController = serverVc
currentWindow.makeKeyAndVisible()
}, completion: nil)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension OfflineFilesViewController : OfflineFilesView {
func playMedia(at url: URL) {
let videoPlayerVc = self.viewController(viewControllerClass: VideoPlayerViewController.self, from: StoryBoardIdentifiers.videoPlayer)
videoPlayerVc.mediaURL = url
videoPlayerVc.modalPresentationStyle = .fullScreen
self.present(videoPlayerVc)
}

Expand All @@ -39,12 +40,7 @@ extension OfflineFilesViewController : OfflineFilesView {
AudioPlayerDataModel.shared.itemURLs = URLs
audioPlayerVc.offlineMode = true
AudioPlayerDataModel.shared.setupQueueMetadata()
if #available(iOS 13.0, *) {
audioPlayerVc.isModalInPresentation = true
}
if UIDevice().userInterfaceIdiom == .pad{
audioPlayerVc.modalPresentationStyle = .fullScreen
}
audioPlayerVc.modalPresentationStyle = .fullScreen
self.present(audioPlayerVc)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension RecentFilesViewController{
AudioPlayerDataModel.shared.queuedItems = items
AudioPlayerDataModel.shared.itemURLs = URLs
AudioPlayerDataModel.shared.setupQueueMetadata()
audioPlayerVc.modalPresentationStyle = .fullScreen
present(audioPlayerVc, animated: true, completion: nil)
}
}
Expand Down Expand Up @@ -85,6 +86,7 @@ extension RecentFilesViewController{
}else{
let videoPlayerVc = self.viewController(viewControllerClass: VideoPlayerViewController.self, from: StoryBoardIdentifiers.videoPlayer)
videoPlayerVc.mediaURL = url
videoPlayerVc.modalPresentationStyle = .fullScreen
present(videoPlayerVc, animated: true, completion: nil)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ class SettingsViewController: BaseUITableViewController {
self.dismiss(animated: false, completion: nil)
LocalStorage.shared.logout{}
let loginVc = self.viewController(viewControllerClass: LoginViewController.self, from: StoryBoardIdentifiers.main)
self.present(loginVc, animated: true, completion: nil)
if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let currentWindow = appDelegate.window{
UIView.transition(with: currentWindow, duration: 0.3, options: .transitionFlipFromRight, animations: {
//removing strong references from all other VC to let ARC automatically delete them from memmory
currentWindow.rootViewController = loginVc
currentWindow.makeKeyAndVisible()
}, completion: nil)
}
}

internal func handleSignOut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class WalkthroughViewController: BaseUIViewController {
let loginVC = mainStoryboard.instantiateViewController(withIdentifier: StoryBoardIdentifiers.loginViewController)

LocalStorage.shared.persistString(string: "completed", key: "walkthrough")
loginVC.modalPresentationStyle = .fullScreen
present(loginVC, animated: true, completion: nil)
}
}
Expand Down

0 comments on commit 9f7769a

Please sign in to comment.