Skip to content

Commit d9d4a1d

Browse files
committed
Show/hide navigationBar when navigating from HomeView
1 parent d34abbb commit d9d4a1d

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

RubyEvents/App.swift

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,80 +11,77 @@ import UIKit
1111

1212
class App {
1313
static var instance = App()
14-
14+
1515
var isTabbed: Bool = true
16-
16+
1717
var sceneDelegate: SceneDelegate?
18-
18+
1919
lazy var navigator = Navigator(delegate: self)
2020
lazy var tabBarController = TabBarController(app: self)
21-
22-
private var currentUnreadMessagesCount: String?
23-
21+
2422
var navigators: [Navigator] {
2523
if isTabbed {
2624
return tabBarController.navigators
2725
}
2826
return [navigator]
2927
}
30-
28+
3129
var viewControllers: [UIViewController] {
3230
navigators.map(\.rootViewController)
3331
}
34-
32+
3533
var window: UIWindow? {
3634
sceneDelegate?.window
3735
}
38-
36+
3937
var isDebug: Bool {
4038
#if DEBUG
4139
return true
4240
#else
4341
return false
4442
#endif
4543
}
46-
44+
4745
var isTestFlight: Bool {
4846
Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
4947
}
50-
48+
5149
var environment: Environment {
5250
if isDebug {
5351
return .development
5452
}
55-
53+
5654
if isTestFlight {
5755
return .staging
5856
}
59-
57+
6058
return .production
6159
}
62-
60+
6361
func start(sceneDelegate: SceneDelegate) {
6462
self.sceneDelegate = sceneDelegate
6563
self.tabBarController.setupTabs()
66-
64+
6765
switchToTabController()
6866
}
69-
67+
7068
func switchToNavigationController() {
7169
sceneDelegate?.window?.rootViewController = navigator.rootViewController
7270
self.isTabbed = false
7371
}
74-
72+
7573
func switchToTabController() {
7674
sceneDelegate?.window?.rootViewController = tabBarController
7775
self.isTabbed = true
7876
}
79-
77+
8078
func navigatorFor(title: String) -> Navigator? {
8179
tabBarController.navigatorFor(title: title)
8280
}
8381
}
8482

8583
extension App: NavigatorDelegate {
8684
func handle(proposal: VisitProposal) -> ProposalResult {
87-
8885
switch proposal.viewController {
8986
case "home":
9087
let viewController = UIHostingController(
@@ -93,8 +90,12 @@ extension App: NavigatorDelegate {
9390
)
9491
)
9592

93+
App.instance.tabBarController.hideNavigationBarFor(title: "Home")
94+
9695
return .acceptCustom(viewController)
9796
default:
97+
App.instance.tabBarController.showNavigationBarFor(title: "Home")
98+
9899
return .accept
99100
}
100101
}

RubyEvents/components/HomeView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,11 @@ struct HomeView: View {
8181
}
8282
}
8383
.onAppear {
84-
navigator?.rootViewController.navigationBar.isHidden = true
85-
84+
App.instance.tabBarController.hideNavigationBarFor(title: "Home")
8685
if !hasLoadedInitialData {
8786
fetchData()
8887
hasLoadedInitialData = true
8988
}
90-
}.onDisappear {
91-
navigator?.rootViewController.navigationBar.isHidden = false
9289
}
9390
}
9491

RubyEvents/controllers/TabBarController.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,25 @@ class TabBarController: UITabBarController {
6262

6363
return navigators[index]
6464
}
65-
66-
var currentTab: String? {
65+
66+
var currentNavigator: Navigator? {
67+
navigatorFor(title: currentTabTitle ?? "")
68+
}
69+
70+
var currentTabTitle: String? {
6771
self.tabBar.selectedItem?.title
6872
}
69-
73+
74+
func hideNavigationBarFor(title: String) {
75+
let navigator = self.navigatorFor(title: title)
76+
navigator?.rootViewController.navigationBar.isHidden = true
77+
}
78+
79+
func showNavigationBarFor(title: String) {
80+
let navigator = self.navigatorFor(title: title)
81+
navigator?.rootViewController.navigationBar.isHidden = false
82+
}
83+
7084
func hideTabBar() {
7185
self.tabBar.isHidden = true
7286
}

0 commit comments

Comments
 (0)