Files
suixinkan_ios_uikit/suixinkan_ios/App/AppUITestRouteDriver.swift
汉秋 a1c031c9b7 Integrate CYLTabBar center scan button and unify UIKit navigation.
Add CYLTabBarController with a global scan entry, promote MainTabBarController to the window root after login, replace RouterPath-based navigation with AppNavigator, and fix Profile diffable cell reconfiguration crashes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 16:36:18 +08:00

96 lines
3.4 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.

//
// AppUITestRouteDriver.swift
// suixinkan
//
// Created by Codex on 2026/6/26.
//
#if DEBUG
import UIKit
/// UI Test Tab push
@MainActor
enum AppUITestRouteDriver {
private static var didApply = false
///
static func applyIfNeeded(services: AppServices = .shared) async {
guard AppUITestLaunchState.isRunningUITests, !didApply else { return }
guard AppUITestLaunchState.pendingMenuTitle != nil
|| AppUITestLaunchState.pendingProfileRouteRawValue != nil else { return }
didApply = true
try? await Task.sleep(nanoseconds: 1_200_000_000)
if let menuTitle = AppUITestLaunchState.pendingMenuTitle {
openHomeMenu(title: menuTitle, services: services)
return
}
if let rawValue = AppUITestLaunchState.pendingProfileRouteRawValue {
openProfileRoute(rawValue: rawValue, services: services)
}
}
///
private static func openHomeMenu(title: String, services: AppServices) {
let resolvedTitle = resolveMenuTitle(title)
guard let item = HomeMenuRouter.debugAllMenuItems().first(where: { $0.title == resolvedTitle }) else {
return
}
services.appNavigator.resetAllStacks()
let resolved = HomeMenuRouter.resolve(uri: item.uri, title: item.title)
switch resolved {
case .tab(let tab):
services.appNavigator.selectTab(tab)
case .orders(let entry):
services.appNavigator.openOrdersEntry(entry)
case .destination(let homeRoute):
services.appNavigator.openHome(homeRoute, policy: .tabRoot(.home), animated: false)
case .unsupported(let uri, let title, _):
services.appNavigator.openHome(.modulePlaceholder(uri: uri, title: title), policy: .tabRoot(.home), animated: false)
case .placeholder(let uri, let title):
services.appNavigator.openHome(.modulePlaceholder(uri: uri, title: title), policy: .tabRoot(.home), animated: false)
}
}
///
private static func openProfileRoute(rawValue: String, services: AppServices) {
let route: ProfileRoute?
switch rawValue {
case "settings":
route = .settings
case "realNameAuth":
route = .realNameAuth
case "accountSwitch":
route = .accountSwitch
case "debugHomeMenus":
route = .debugHomeMenus
case "agreement.about":
route = .agreement(.about)
case "agreement.userAgreement":
route = .agreement(.userAgreement)
case "agreement.privacyPolicy":
route = .agreement(.privacyPolicy)
default:
route = nil
}
guard let route else { return }
services.appNavigator.resetAllStacks()
services.appNavigator.openProfile(route, policy: .tabRoot(.profile), animated: false)
}
/// UI Test
private static func resolveMenuTitle(_ title: String) -> String {
switch title {
case "系统设置":
return "设置中心"
default:
return title
}
}
}
#endif