Skip to content

Instantly share code, notes, and snippets.

@AlexGladkov
Created October 18, 2018 18:07
Show Gist options
  • Save AlexGladkov/001fc2fdc0134b7a7a5a23a286876e41 to your computer and use it in GitHub Desktop.
Save AlexGladkov/001fc2fdc0134b7a7a5a23a286876e41 to your computer and use it in GitHub Desktop.
//
// BaseRouting.swift
// sddclient
//
// Created by Гладков Алексей on 10.04.18.
// Copyright © 2018 SDD LLC. All rights reserved.
//
import Foundation
import UIKit
protocol BaseRouting {
func setViewController(viewController: UIViewController)
func routeToScreen(with key: ScreenKey, data: Any?)
func presentScreen(with key: ScreenKey, data: Any?)
func exit()
}
class RoutingLayer: NSObject, BaseRouting {
weak var viewController: UIViewController?
func setViewController(viewController: UIViewController) {
self.viewController = viewController
}
func routeToScreen(with key: ScreenKey, data: Any?) {
}
func presentScreen(with key: ScreenKey, data: Any?) {
}
func exit() {
if (isModal()) {
viewController?.dismiss(animated: true, completion: nil)
} else {
viewController?.navigationController?.popViewController(animated: true)
}
}
func isModal() -> Bool {
guard let strongVC = viewController else { return true }
if let navigationController = strongVC.navigationController {
if navigationController.viewControllers.first != strongVC {
return false
}
}
if strongVC.presentingViewController != nil {
return true
}
if strongVC.navigationController?.presentingViewController?.presentedViewController == strongVC.navigationController {
return true
}
if strongVC.tabBarController?.presentingViewController is UITabBarController {
return true
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment