Files
suixinkan_uikit/suixinkan/App/AppRouter.swift
汉秋 b7d74905b7 Add login flow, session routing, and MainTab shell aligned with reference UI.
Implement token-based root routing, Android-matched login screen, five-slot MainTabBar with scan action, and placeholder tab pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 15:12:34 +08:00

58 lines
1.7 KiB
Swift
Raw 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.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.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()
})
}
}