NavigationViewController.swift 1.88 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() {
        setStartControllers()
        view.backgroundColor = .blue
        delegate = self
    }
}

// MARK: - Helpers
extension NavigationViewController {
    private func setStartControllers() {
        let tabsViewController = TabsViewController()
        let browserHomeViewController = BrowserHomeViewController(url: nil, currentTabId: nil)
        let payloadViewController = PayloadViewController()
        let cachingManager = CachingManager.shared
        if cachingManager.isFirstAppLoad == false {
            setViewControllers([tabsViewController, browserHomeViewController, payloadViewController], animated: true)
            cachingManager.isFirstAppLoad.toggle()
        } else {
            setViewControllers([tabsViewController, browserHomeViewController], 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)
        }
        return nil
    }
}