Files
suixinkan_ios_uikit/suixinkan_ios/App/Navigation/TabNavigationController.swift
汉秋 1a6d4a1791 Fix home navigation bar visibility and hide scan tab title.
Home uses a custom top bar, so TabNavigationController now syncs system nav bar visibility with the stack top; remove the scan tab text label to show icon only.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 08:59:31 +08:00

99 lines
4.0 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.

//
// TabNavigationController.swift
// suixinkan
//
import UIKit
@MainActor
/// Tab UIKit Tab
final class TabNavigationController: UINavigationController {
let appTab: AppTab
private let services: AppServices
///
init(tab: AppTab, services: AppServices) {
self.appTab = tab
self.services = services
super.init(nibName: nil, bundle: nil)
delegate = self
navigationBar.prefersLargeTitles = false
setViewControllers([tab.makeRootViewController(services: services)], animated: false)
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/// Push TabBar
func push(route: AppRoute, animated: Bool = true) {
let viewController = AppRouteViewControllerFactory.makeViewController(for: route, services: services)
viewController.hidesBottomBarWhenPushed = route.hidesTabBarWhenPushed
pushViewController(viewController, animated: animated)
}
/// Push push
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
updateNavigationBarVisibility(for: viewController, animated: animated)
super.pushViewController(viewController, animated: animated)
}
///
override func setViewControllers(_ viewControllers: [UIViewController], animated: Bool) {
if let topViewController = viewControllers.last {
updateNavigationBarVisibility(for: topViewController, animated: animated)
}
super.setViewControllers(viewControllers, animated: animated)
}
///
override func popViewController(animated: Bool) -> UIViewController? {
let poppedViewController = super.popViewController(animated: animated)
if !animated, let topViewController {
updateNavigationBarVisibility(for: topViewController, animated: false)
}
return poppedViewController
}
///
override func popToRootViewController(animated: Bool) -> [UIViewController]? {
let poppedViewControllers = super.popToRootViewController(animated: animated)
if !animated, let topViewController {
updateNavigationBarVisibility(for: topViewController, animated: false)
}
return poppedViewControllers
}
///
override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
let poppedViewControllers = super.popToViewController(viewController, animated: animated)
if !animated, let topViewController {
updateNavigationBarVisibility(for: topViewController, animated: false)
}
return poppedViewControllers
}
///
private func shouldHideNavigationBar(for viewController: UIViewController) -> Bool {
viewController is HomeViewController
}
///
private func updateNavigationBarVisibility(for viewController: UIViewController, animated: Bool) {
setNavigationBarHidden(shouldHideNavigationBar(for: viewController), animated: animated)
}
}
extension TabNavigationController: UINavigationControllerDelegate {
///
func navigationController(
_ navigationController: UINavigationController,
willShow viewController: UIViewController,
animated: Bool
) {
updateNavigationBarVisibility(for: viewController, animated: animated)
}
}