Fix Safari VCs being presented incorrectly from peek/pop, cleanup VC previewing code

This commit is contained in:
Shadowfacts 2018-10-20 15:35:56 -04:00
parent eb9e1276df
commit d9fa189848
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 2 additions and 48 deletions

View File

@ -7,24 +7,12 @@
//
import UIKit
enum PreviewCommitType {
case nav
case modal
}
import SafariServices
protocol PreviewViewControllerProvider {
func getPreviewViewController(forLocation location: CGPoint, sourceViewController: UIViewController) -> UIViewController?
func getPreviewCommitType(forViewController viewController: UIViewController) -> PreviewCommitType
}
extension PreviewViewControllerProvider {
func getPreviewCommitType(forViewController viewController: UIViewController) -> PreviewCommitType {
return viewController is LargeImageViewController ? .modal : .nav
}
}
@objc extension UITableViewController: UIViewControllerPreviewingDelegate {
@ -41,44 +29,10 @@ extension PreviewViewControllerProvider {
}
public func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
if viewControllerToCommit is LargeImageViewController {
if viewControllerToCommit is LargeImageViewController || viewControllerToCommit is SFSafariViewController {
present(viewControllerToCommit, animated: false)
} else {
navigationController!.pushViewController(viewControllerToCommit, animated: false)
}
}
}
//class PreviewingController: NSObject, UIViewControllerPreviewingDelegate {
//
// var currentCommitType: PreviewCommitType?
// var owner: UIViewController?
//
// init(owner: UIViewController) {
// self.owner = owner
// }
//
// func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
// if let owner = owner as? UITableViewController,
// let indexPath = owner.tableView.indexPathForRow(at: location),
// let cell = owner.tableView.cellForRow(at: indexPath) as? UITableViewCell & PreviewViewControllerProvider {
// let cellLocation = cell.convert(location, from: owner.tableView)
// if let vc = cell.getPreviewViewController(forLocation: cellLocation, sourceViewController: owner) {
// currentCommitType = cell.getPreviewCommitType(forViewController: vc)
// previewingContext.sourceRect = owner.tableView.rectForRow(at: indexPath)
// return vc
// }
// }
// return nil
// }
//
// func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
// switch currentCommitType ?? .nav {
// case .modal:
// owner?.present(viewControllerToCommit, animated: false)
// case .nav:
// owner?.navigationController!.pushViewController(viewControllerToCommit, animated: false)
// }
// }
//
//}