Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chat-iOS/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
if #available(iOS 13, *) {
} else {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = Routes.decideRootViewController()
window?.rootViewController = RootViewController()
window?.makeKeyAndVisible()
}
return true
Expand Down
72 changes: 72 additions & 0 deletions chat-iOS/App/RootViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// RootViewController.swift
// chat-iOS
//
// Created by 戸高新也 on 2020/07/13.
//

import UIKit
import FirebaseAuth

class RootViewController: UIViewController {

static var instance: RootViewController {
return UIApplication.shared.keyWindow!.rootViewController as! RootViewController
}

enum ViewType {
case login
case main
}

private var viewType: ViewType? {
didSet {
guard let type = viewType, oldValue != type else { return }
switch type {
case .login:
currentViewController = UINavigationController(rootViewController: AuthTopViewBuilder.create())
case .main:
currentViewController = MainTabBarViewBuilder.create()
}
}
}

private(set) var currentViewController: UIViewController? {
didSet {
guard let currentViewController = currentViewController else { return }

addChild(currentViewController)
view.addSubview(currentViewController.view)
currentViewController.didMove(toParent: self)
currentViewController.view.frame = view.bounds

guard let oldViewController = oldValue else { return }

view.sendSubviewToBack(currentViewController.view)
UIView.transition(from: oldViewController.view, to: currentViewController.view, duration: 0.35, options: .transitionCrossDissolve) { _ in
oldViewController.willMove(toParent: nil)
oldViewController.view.removeFromSuperview()
oldViewController.removeFromParent()
}
}
}

override func loadView() {
super.loadView()
view.backgroundColor = .white
}

override func viewDidLoad() {
super.viewDidLoad()

if Auth.auth().currentUser?.uid == nil {
self.viewType = .login
} else {
self.viewType = .main
}
}

func transition(to type: ViewType) {
self.viewType = type
}
}
2 changes: 1 addition & 1 deletion chat-iOS/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)
window?.rootViewController = Routes.decideRootViewController()
window?.rootViewController = RootViewController()
window?.makeKeyAndVisible()
}
}
2 changes: 1 addition & 1 deletion chat-iOS/Views/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension LoginViewController: LoginViewPresenterOutput {

func transitionToMainTabBar(withUser user: User) {
//TODO:- userを使ってMainTabBarへの遷移処理を書く
print(user.displayName)
RootViewController.instance.transition(to: .main)
}

func showAlert(withMessage message: String) {
Expand Down