iOS 17.4 SwiftUI .toolbar(.hidden, for: .tabBar) not work

TabView {
            SummaryView()
                .toolbar(.hidden, for: .tabBar, .bottomBar)
                .tabItem { Text("Title.Summary") }
                .tag(TabItems.summary)
            CalendarView()
                .toolbar(.hidden, for: .tabBar, .bottomBar)
                .tabItem { Text("Title.Calendar") }
                .tag(TabItems.calendar)
            EventTypeView()
                .toolbar(.hidden, for: .tabBar, .bottomBar)
                .tabItem { Text("Title.EventType") }
                .tag(TabItems.group)
            LectureView()
                .toolbar(.hidden, for: .tabBar, .bottomBar)
                .tabItem { Text("Title.Lecture") }
                .tag(TabItems.lecture)
            NotificationView()
                .toolbar(.hidden, for: .tabBar, .bottomBar)
                .tabItem { Text("Title.Notifications") }
                .tag(TabItems.notification)
}

Tabbar is hidden when first opened but tabbar is appeared when I change tab selection. I tested it on iOS 17.1, iOS 17.4, and this bug is only appeared in iOS 17.4.

Post not yet marked as solved Up vote post of LeeJaeho Down vote post of LeeJaeho
585 views

Replies

I've run into all sorts of problems with .toolbar/.tabBar in iOS 17.4 which suddenly stopped working right after over a year of unchanged code. In the end I came up with this convoluted code where I use a @Binding to control the .hidden/.visible state of the tab bar, and set the variable in various .onAppear/.onDisappear handlers.

  • @Neufsters First of all, thanks for your solution. Even though it's not perfect, I could make it to look my app view alright at least. Now I'm waiting for fix from Apple update but still I can see it doesn't work on ios 17.4.1, the latest one. Maybe it would be fixed on ios 17.5? I'm a ios beginner so I don't know when Apple usually fix. When do you guys think it will be fixed and is there any other better way for it?

Add a Comment

Can you try .tabViewStyle(.page) on ios 17.4

Yes, it could be an alternative. I also tried that way and it works perfectly, I mean no visible tabBar. But I wanted not to apply a gesture to change views on tabView. I want it to work by only tapping on tabBar. So that way is not a perfect way if you don't want gestures on tabView. Or other way to prevent gestures?

Converting to .tabViewStyle(.page) also breaks inner Navigation Bars or at least Safe Area for me. It would require a severe rewrite of the whole app UI structure.

iOS 17.5 beta is out and no fix for this. How is it possible SwiftUI cannot be a reliable tool after this much time.

Ah really? It's still not fixed on iOS 17.5 Beta? Actually I didn't expect that Apple would fix quickly haha.. I guess at least we have to wait for iOS 18. Since iOS 14, SwiftUI looked nice and useful, so I strongly insisted converting to SwiftUI from UIKit on my company. I did and it took longer time than expected. But the result of strongly pushing is like that... The executives and team chief has lost expectations on SwiftUI, and even they think it's better to go back to UIKit. Very unreliable, SwiftUI is, I agree.

This is what I did for my tabs and no longer have the problem with system tabbar showing up unexpectedly.

    @State var activeTab: Screen = .home
    var body: some View {
        TabView(selection: $activeTab) {
            switch activeTab {
            case .home:
                HomeRoot()
                    .tag(Screen.home)
            case .menu:
                MenuRoot()
                    .tag(Screen.menu)
            case .rewards:
                RewardsRoot()
                    .tag(Screen.rewards)
            case .scan:
                Scan()
                    .tag(Screen.scan)
            default:
                EmptyView()
            }
        }
        .safeAreaInset(edge: .bottom) {
            TabBarView(
                activeTab: $activeTab
            )
        }
    }