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.

63 lines
2.1 KiB

6 years ago
  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. weak 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.delegate as! AppDelegate).window
  23. }
  24. func viewControllerFromStoryboard<T: UIViewController>(of type: T.Type) -> T {
  25. return UIStoryboard(name: storyboardName, bundle: nil).instantiateViewController(withIdentifier: String(describing: T.self)) as! T
  26. }
  27. func openMainViewIn(window: UIWindow) {
  28. let view = self.getMainView()
  29. window.rootViewController = view
  30. }
  31. func openMainViewAsNavigationControllerIn(window: UIWindow) {
  32. let view = self.getMainView()
  33. let nav = UINavigationController.init(rootViewController: view)
  34. window.rootViewController = nav
  35. }
  36. func openMainView(source: UIViewController) {
  37. let mainView = self.getMainView()
  38. source.present(mainView, animated: true, completion: nil)
  39. }
  40. func pushMainView(on source: UIViewController) {
  41. let mainView = self.getMainView()
  42. source.navigationController?.pushViewController(mainView, animated: true)
  43. }
  44. func pushMainView(in source: UINavigationController) {
  45. let mainView = self.getMainView()
  46. source.pushViewController(mainView, animated: true)
  47. }
  48. func openViewControllerWithNavigation(viewController: UIViewController, source: UIViewController) {
  49. let nav = UINavigationController(rootViewController: viewController)
  50. source.present(nav, animated: true, completion: nil)
  51. }
  52. }