You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
2.6 KiB

//
// WireframeInput.swift
// GMERemittance
//
// Created by gme_2 on 24/08/2018.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
protocol WireframeInput {
var window: UIWindow? {get}
var view: UIViewController! {get}
var storyboardName: String {get}
func openMainView(source: UIViewController)
func pushMainView(on source: UIViewController)
func pushMainView(in source: UINavigationController)
func getMainView() -> UIViewController
func openMainViewIn(window: UIWindow)
func openViewControllerWithNavigation(viewController: UIViewController, source: UIViewController)
}
extension WireframeInput {
var window: UIWindow? {
return UIApplication.shared.keyWindow
}
func viewControllerFromStoryboard<T: UIViewController>(of type: T.Type) -> T {
return UIStoryboard(name: storyboardName, bundle: nil).instantiateViewController(
withIdentifier: String(describing: T.self)
) as! T
}
func openMainViewIn(window: UIWindow) {
let view = self.getMainView()
window.rootViewController = view
}
func openMainViewAsNavigationControllerIn(window: UIWindow) {
let view = self.getMainView()
let nav = UINavigationController.init(rootViewController: view)
window.rootViewController = nav
}
func openMainView(source: UIViewController) {
let mainView = self.getMainView()
source.present(mainView, animated: true, completion: nil)
}
func pushMainView(on source: UIViewController) {
let mainView = self.getMainView()
source.push(mainView, animated: true)
}
func pushMainView(in source: UINavigationController) {
let mainView = self.getMainView()
source.push(mainView, animated: true)
}
func openViewControllerWithNavigation(viewController: UIViewController, source: UIViewController) {
let nav = UINavigationController(rootViewController: viewController)
nav.modalPresentationStyle = .fullScreen
source.present(nav, animated: true, completion: nil)
}
}
extension UIViewController{
func push(_ viewController: UIViewController, animated: Bool){
if let tabBarController = self.tabBarController{
tabBarController.navigationController?.pushViewController(viewController, animated: animated)
return
}
if let navigationController = self.navigationController{
navigationController.pushViewController(viewController, animated: animated)
return
}
if let navigation = self as? UINavigationController{
navigation.pushViewController(viewController, animated: animated)
}
}
}