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.

65 lines
2.0 KiB

  1. //
  2. // WireframeInput.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 24/08/2018.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. protocol WireframeInput {
  10. var window: UIWindow? {get}
  11. var view: UIViewController! {get}
  12. var storyboardName: String {get}
  13. func openMainView(source: UIViewController)
  14. func pushMainView(on source: UIViewController)
  15. func pushMainView(in source: UINavigationController)
  16. func getMainView() -> UIViewController
  17. func openMainViewIn(window: UIWindow)
  18. func openViewControllerWithNavigation(viewController: UIViewController, source: UIViewController)
  19. }
  20. extension WireframeInput {
  21. var window: UIWindow? {
  22. return UIApplication.shared.keyWindow
  23. }
  24. func viewControllerFromStoryboard<T: UIViewController>(of type: T.Type) -> T {
  25. return UIStoryboard(name: storyboardName, bundle: nil).instantiateViewController(
  26. withIdentifier: String(describing: T.self)
  27. ) as! T
  28. }
  29. func openMainViewIn(window: UIWindow) {
  30. let view = self.getMainView()
  31. window.rootViewController = view
  32. }
  33. func openMainViewAsNavigationControllerIn(window: UIWindow) {
  34. let view = self.getMainView()
  35. let nav = UINavigationController.init(rootViewController: view)
  36. window.rootViewController = nav
  37. }
  38. func openMainView(source: UIViewController) {
  39. let mainView = self.getMainView()
  40. source.present(mainView, animated: true, completion: nil)
  41. }
  42. func pushMainView(on source: UIViewController) {
  43. let mainView = self.getMainView()
  44. source.navigationController?.pushViewController(mainView, animated: true)
  45. }
  46. func pushMainView(in source: UINavigationController) {
  47. let mainView = self.getMainView()
  48. source.pushViewController(mainView, animated: true)
  49. }
  50. func openViewControllerWithNavigation(viewController: UIViewController, source: UIViewController) {
  51. let nav = UINavigationController(rootViewController: viewController)
  52. source.present(nav, animated: true, completion: nil)
  53. }
  54. }