generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 81
[PM-26060] Consolidate TabNavigator to BitwardenKit #2105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48a76c1
Move TabRepresentable
KatherineInCode ddc35e8
PM to test
KatherineInCode 6fe4ba6
BWA to test
KatherineInCode 3dbd437
Move TabNavigator
KatherineInCode d658d35
PM to test
KatherineInCode 35bc6a0
Adjust locations
KatherineInCode 53279ce
Delete
KatherineInCode 0d64bd9
Adjust
KatherineInCode c36e0c1
Remove comments
KatherineInCode 9b1a790
Merge branch 'main' into pm-26060/consolidate-tab-navigator
KatherineInCode 81da0aa
Fix typo
KatherineInCode 3f5ca4f
Merge branch 'main' into pm-26060/consolidate-tab-navigator
KatherineInCode 9c20afd
Merge branch 'main' into pm-26060/consolidate-tab-navigator
KatherineInCode 73d7017
Fix typo
KatherineInCode df936bb
Adjust per Claude
KatherineInCode 7a4cafc
Merge branch 'main' into pm-26060/consolidate-tab-navigator
KatherineInCode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
AuthenticatorShared/UI/Platform/Application/Utilities/TabNavigator.swift
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
AuthenticatorShared/UI/Platform/Application/Views/BitwardenTabBarController.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import BitwardenKit | ||
| import UIKit | ||
|
|
||
| // MARK: - BitwardenTabBarController | ||
|
|
||
| /// A `UITabBarController` subclass conforming to `TabNavigator`. This class manages | ||
| /// a set of tabs and handles dynamic appearance changes between light/dark mode. | ||
| /// | ||
| class BitwardenTabBarController: UITabBarController, TabNavigator { | ||
| // MARK: Properties | ||
|
|
||
| /// The tabs used in the UITabBarController, mapping each `TabRoute` to its respective `Navigator`. | ||
| private var tabsAndNavigators: [TabRoute: any Navigator] = [:] | ||
|
|
||
| // MARK: AlertPresentable | ||
|
|
||
| var rootViewController: UIViewController? { | ||
| self | ||
| } | ||
|
|
||
| // MARK: TabNavigator | ||
|
|
||
| func navigator<Tab: TabRepresentable>(for tab: Tab) -> Navigator? { | ||
| viewControllers?[tab.index] as? Navigator | ||
| } | ||
|
|
||
| func setNavigators<Tab: Hashable & TabRepresentable>(_ tabs: [Tab: Navigator]) { | ||
| tabsAndNavigators = tabs as? [TabRoute: Navigator] ?? [:] | ||
|
|
||
| viewControllers = tabs | ||
| .sorted { $0.key.index < $1.key.index } | ||
| .compactMap { tab in | ||
| guard let viewController = tab.value.rootViewController else { return nil } | ||
| viewController.tabBarItem.title = tab.key.title | ||
| viewController.tabBarItem.image = tab.key.image | ||
| viewController.tabBarItem.selectedImage = tab.key.selectedImage | ||
| return viewController | ||
| } | ||
| } | ||
|
|
||
| // MARK: Lifecycle | ||
|
|
||
| /// Called when the trait collection (such as light/dark mode) changes. | ||
| /// | ||
| /// UIKit does not seem to refresh the tab bar icon images dynamically when switching between | ||
| /// light/dark mode in mid-session. This override ensures the icons update correctly by re-applying | ||
| /// the navigators with the current tabs. | ||
| /// | ||
| override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | ||
| super.traitCollectionDidChange(previousTraitCollection) | ||
|
|
||
| if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) { | ||
| setNavigators(tabsAndNavigators) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import BitwardenKit | ||
| import BitwardenResources | ||
| import UIKit | ||
|
|
||
|
|
||
34 changes: 34 additions & 0 deletions
34
BitwardenKit/UI/Platform/Application/Utilities/Mocks/MockTabNavigator.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import BitwardenKit | ||
| import UIKit | ||
|
|
||
| public final class MockTabNavigator: TabNavigator { | ||
| public var navigators: [Navigator] = [] | ||
| public var navigatorForTabValue: Int? | ||
| public var navigatorForTabReturns: Navigator? | ||
| public var rootViewController: UIViewController? | ||
| public var selectedIndex: Int = 0 | ||
|
|
||
| public init() {} | ||
|
|
||
| public func setChildren(_ navigators: [Navigator]) { | ||
| self.navigators = navigators | ||
| } | ||
|
|
||
| public func navigator<Tab: TabRepresentable>(for tab: Tab) -> Navigator? { | ||
| navigatorForTabValue = tab.index | ||
| return navigatorForTabReturns | ||
| } | ||
|
|
||
| public func present( | ||
| _ viewController: UIViewController, | ||
| animated: Bool, | ||
| overFullscreen: Bool, | ||
| onCompletion: (() -> Void)?, | ||
| ) {} | ||
|
|
||
| public func setNavigators<Tab: Hashable & TabRepresentable>(_ tabs: [Tab: Navigator]) { | ||
| navigators = tabs | ||
| .sorted { $0.key.index < $1.key.index } | ||
| .map(\.value) | ||
| } | ||
| } |
3 changes: 1 addition & 2 deletions
3
.../Application/Utilities/TabNavigator.swift โ .../Application/Utilities/TabNavigator.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ication/Utilities/TabNavigatorTests.swift โ ...iews/BitwardenTabBarControllerTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import BitwardenKit | ||
| import BitwardenResources | ||
| import UIKit | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.