Files
suixinkan_uikit/suixinkan/App/AppRouter.swift
汉秋 005349f8e6 模块化 AppStore 并完善素材管理与个人空间设置。
将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 11:01:08 +08:00

58 lines
1.7 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppRouter.swift
// suixinkan
//
import UIKit
///
enum AppRouter {
enum Root {
case login
case mainTab
}
/// Tab
static func makeRootViewController() -> UIViewController {
makeViewController(for: AppStore.shared.session.isLoggedIn ? .mainTab : .login)
}
///
static func setRoot(_ root: Root, on window: UIWindow?, animated: Bool = true) {
setRoot(makeViewController(for: root), on: window, animated: animated)
}
///
static func refreshRoot(on window: UIWindow?, animated: Bool = true) {
setRoot(AppStore.shared.session.isLoggedIn ? .mainTab : .login, on: window, animated: animated)
}
private static func makeViewController(for root: Root) -> UIViewController {
switch root {
case .login:
return UINavigationController(rootViewController: LoginViewController())
case .mainTab:
return MainTabBarController()
}
}
private static func setRoot(_ viewController: UIViewController, on window: UIWindow?, animated: Bool) {
guard let window else { return }
guard animated, let snapshot = window.snapshotView(afterScreenUpdates: true) else {
window.rootViewController = viewController
return
}
viewController.view.addSubview(snapshot)
window.rootViewController = viewController
UIView.animate(withDuration: 0.25, animations: {
snapshot.alpha = 0
}, completion: { _ in
snapshot.removeFromSuperview()
})
}
}