NavigationViewController.swift 2.13 KB
//
//  NavigationControllerViewController.swift
//  browser
//
//  Created by Artem Talko on 26.09.2023.
//

import UIKit

final class NavigationViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initViewController()
    }

    private func initViewController() {
        view.backgroundColor = .black
        delegate = self
        
        setStartControllers()
    }
}

// MARK: - Helpers
extension NavigationViewController {
    private func setStartControllers() {
        let payloadViewController = PayloadViewController()
        let removeAdvertViewController = RemoveAdvertViewController()
        let cachingManager = CachingManager.shared
        
        if cachingManager.isFirstAppLoad == false {
            setViewControllers([removeAdvertViewController, payloadViewController], animated: true)
            cachingManager.isFirstAppLoad.toggle()
        } else {
            setViewControllers([removeAdvertViewController], animated: true)
        }
    }
}

//MARK: Navigation Controller delegate
extension NavigationViewController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController,
                              animationControllerFor operation: UINavigationController.Operation,
                              from fromVC: UIViewController,
                              to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        if (fromVC is BrowserHomeViewController && toVC is TabsViewController) {
            return OpenTabsTransition(operation: operation)
        }
        
        if (fromVC is TabsViewController && toVC is BrowserHomeViewController) {
            return OpenTabsTransition(operation: operation)
        }
        
        if (fromVC is RemoveAdvertViewController && toVC is BrowserHomeViewController) {
            return OpenBrowserHomeTransition(operation: operation)
        }
        if (fromVC is BrowserHomeViewController && toVC is RemoveAdvertViewController) {
            return OpenBrowserHomeTransition(operation: operation)
        }
        return nil
    }
}