Hide TabView and place toolbar item on its place

Hi Folks,

I would like it so that when I press the button on the HomeScreen, the TabView hides and the toolbar item appears in its place.

Currently, the toolbar item stacks on top of the TabView. However, when I try to hide the TabView, with an if condition for example, the screens turn black. I think it's because of the screen calls in the TabView. Is there an option to achieve what I want?

I'm new to SwiftUI, so I'm very glad for any Solutions or advices.

struct NavBar: View {
    var body: some View {
        TabView {
            HomeScreen()
                .tabItem {
                    Label(
                        "Home",
                        systemImage: "house"
                    )
                }
            ...
        }
    }
}
struct HomeScreen: View {
    @State private var showDeleteButton = false

    var body: some View {

        Button("Show/Dissmiss Delete Button", action: {
            showDeleteButton.toggle()
        }).toolbar {
            if showDeleteButton {
                ToolbarItem(placement: .bottomBar) {
                    Button("Delete", action: {})
                }
            }
        }
    }
}

Replies

Hi @okayest_dev ,

It seems like you're asking if you can hide the tabs and show a toolbar item in its place, correct?

If so, there's no way to hide the tabs since that hinders the user's ability to navigate. You can choose the placement as I see you've done with .bottomBar, but that's the best you can do.

The reason your screen turns black when you hide the TabView is because that's the entire view being shown on your screen. What you're trying to do is actually hide the tabItem, but again, make sure the user always has the option to navigate within the app. See the best practices here: https://developer.apple.com/design/human-interface-guidelines/tab-bars#Best-practices