Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5086 from corona-warn-app/fix/14908-EOL-TabBar-un…
Browse files Browse the repository at this point in the history
…changed-and-Overview-still-visible-after-EOL-and-without-AppRestart

Fix/14908 EOL - TabBar unchanged after EOL and without AppRestart
  • Loading branch information
30mar authored Mar 13, 2023
2 parents 5c6c6cc + f2bd49e commit 708fdff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, CoronaWarnAppDelegate, Re

// Cleanup recycle-bin. Remove old entries.
recycleBin.cleanup()

// Refresh Tabbar if needed
coordinator.updateTabbarIfNeeded()
}

func applicationDidEnterBackground(_ application: UIApplication) {
Expand Down
34 changes: 25 additions & 9 deletions src/xcode/ENA/ENA/Source/RootCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class RootCoordinator: NSObject, RequiresAppDependencies, UITabBarControllerDele
return viewController
}()

// swiftlint:disable function_body_length
func showHome(enStateHandler: ENStateHandler, route: Route?, startupErrors: [Error]) {
// only create and init the whole view stack if not done before
// there for we check if the homeCoordinator exists
Expand Down Expand Up @@ -241,22 +240,39 @@ class RootCoordinator: NSObject, RequiresAppDependencies, UITabBarControllerDele
)
self.diaryCoordinator = diaryCoordinator

setupTabbar()
}

func updateTabbarIfNeeded() {
guard let viewControllers = tabBarController.viewControllers else { return }

// Hibernation
if CWAHibernationProvider.shared.isHibernationState, viewControllers.count == 5 {
setupTabbar()
}
// No Hibernation
else if !CWAHibernationProvider.shared.isHibernationState, viewControllers.count == 3 {
setupTabbar()
}
}

private func setupTabbar() {
// Tabbar
let startTabBarItem = UITabBarItem(
title: AppStrings.Tabbar.homeTitle,
image: UIImage(named: "Icons_Tabbar_Home"),
selectedImage: UIImage(named: "Icons_Tabbar_Home_Selected")
)
startTabBarItem.accessibilityIdentifier = AccessibilityIdentifiers.TabBar.home
homeCoordinator.rootViewController.tabBarItem = startTabBarItem
homeCoordinator?.rootViewController.tabBarItem = startTabBarItem

let certificatesTabBarItem = UITabBarItem(
title: AppStrings.Tabbar.certificatesTitle,
image: UIImage(named: "Icons_Tabbar_Certificates"),
selectedImage: UIImage(named: "Icons_Tabbar_Certificates_Selected")
)
certificatesTabBarItem.accessibilityIdentifier = AccessibilityIdentifiers.TabBar.certificates
healthCertificatesTabCoordinator.viewController.tabBarItem = certificatesTabBarItem
healthCertificatesTabCoordinator?.viewController.tabBarItem = certificatesTabBarItem

// CWA Hibernation hides scanner and check-in tab
if !cwaHibernationProvider.isHibernationState {
Expand All @@ -275,7 +291,7 @@ class RootCoordinator: NSObject, RequiresAppDependencies, UITabBarControllerDele
selectedImage: UIImage(named: "Icons_Tabbar_Checkin_Selected")
)
eventsTabBarItem.accessibilityIdentifier = AccessibilityIdentifiers.TabBar.checkin
checkinTabCoordinator.viewController.tabBarItem = eventsTabBarItem
checkinTabCoordinator?.viewController.tabBarItem = eventsTabBarItem
}

let diaryTabBarItem = UITabBarItem(
Expand All @@ -284,18 +300,18 @@ class RootCoordinator: NSObject, RequiresAppDependencies, UITabBarControllerDele
selectedImage: UIImage(named: "Icons_Tabbar_Diary_Selected")
)
diaryTabBarItem.accessibilityIdentifier = AccessibilityIdentifiers.TabBar.diary
diaryCoordinator.viewController.tabBarItem = diaryTabBarItem
diaryCoordinator?.viewController.tabBarItem = diaryTabBarItem

tabBarController.tabBar.tintColor = .enaColor(for: .tint)
tabBarController.tabBar.unselectedItemTintColor = .enaColor(for: .textPrimary2)
tabBarController.delegate = self

let tabBarViewControllers = [
homeCoordinator.rootViewController,
healthCertificatesTabCoordinator.viewController,
homeCoordinator?.rootViewController,
healthCertificatesTabCoordinator?.viewController,
cwaHibernationProvider.isHibernationState ? nil : universalScannerDummyViewController,
cwaHibernationProvider.isHibernationState ? nil : checkinTabCoordinator.viewController,
diaryCoordinator.viewController
cwaHibernationProvider.isHibernationState ? nil : checkinTabCoordinator?.viewController,
diaryCoordinator?.viewController
].compactMap { $0 }
tabBarController.setViewControllers(tabBarViewControllers, animated: false)

Expand Down

0 comments on commit 708fdff

Please sign in to comment.