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

4 years ago
4 years ago
5 years ago
4 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. 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.push(mainView, animated: true)
  45. }
  46. func pushMainView(in source: UINavigationController) {
  47. let mainView = self.getMainView()
  48. source.push(mainView, animated: true)
  49. }
  50. func openViewControllerWithNavigation(viewController: UIViewController, source: UIViewController) {
  51. let nav = UINavigationController(rootViewController: viewController)
  52. nav.modalPresentationStyle = .fullScreen
  53. source.present(nav, animated: true, completion: nil)
  54. }
  55. }
  56. extension UIViewController{
  57. func push(_ viewController: UIViewController, animated: Bool){
  58. if let tabBarController = self.tabBarController{
  59. tabBarController.navigationController?.pushViewController(viewController, animated: animated)
  60. return
  61. }
  62. if let navigationController = self.navigationController{
  63. navigationController.pushViewController(viewController, animated: animated)
  64. return
  65. }
  66. if let navigation = self as? UINavigationController{
  67. navigation.pushViewController(viewController, animated: animated)
  68. }
  69. }
  70. }