85 lines
2.5 KiB
Swift
85 lines
2.5 KiB
Swift
//
|
|
// AccountSwitchingContainerViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 11/11/20.
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class AccountSwitchingContainerViewController: UIViewController {
|
|
|
|
private(set) var root: TuskerRootViewController
|
|
|
|
init(root: TuskerRootViewController) {
|
|
self.root = root
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
embedChild(root)
|
|
}
|
|
|
|
func setRoot(_ newRoot: TuskerRootViewController, animating direction: AnimationDirection) {
|
|
let oldRoot = self.root
|
|
if direction == .none {
|
|
oldRoot.removeViewAndController()
|
|
}
|
|
self.root = newRoot
|
|
embedChild(newRoot)
|
|
|
|
if direction != .none {
|
|
if UIAccessibility.prefersCrossFadeTransitions {
|
|
newRoot.view.alpha = 0
|
|
|
|
UIView.animate(withDuration: 0.4, delay: 0, options: .curveEaseInOut) {
|
|
newRoot.view.alpha = 1
|
|
oldRoot.view.alpha = 0
|
|
} completion: { (_) in
|
|
oldRoot.removeViewAndController()
|
|
}
|
|
} else {
|
|
let sign: CGFloat = direction == .downwards ? -1 : 1
|
|
let newInitialOffset = sign * view.bounds.height
|
|
|
|
newRoot.view.transform = CGAffineTransform(translationX: 0, y: newInitialOffset)
|
|
|
|
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseInOut) {
|
|
newRoot.view.transform = .identity
|
|
oldRoot.view.transform = CGAffineTransform(translationX: 0, y: -newInitialOffset)
|
|
} completion: { (_) in
|
|
oldRoot.removeViewAndController()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AccountSwitchingContainerViewController {
|
|
enum AnimationDirection {
|
|
case none, downwards, upwards
|
|
}
|
|
}
|
|
|
|
extension AccountSwitchingContainerViewController: TuskerRootViewController {
|
|
func presentCompose() {
|
|
root.presentCompose()
|
|
}
|
|
|
|
func select(tab: MainTabBarViewController.Tab) {
|
|
root.select(tab: tab)
|
|
}
|
|
|
|
func getTabController(tab: MainTabBarViewController.Tab) -> UIViewController? {
|
|
root.getTabController(tab: tab)
|
|
}
|
|
}
|