Home > Blockchain >  How to hide empty space caused by a Navigation View in SwiftUI?
How to hide empty space caused by a Navigation View in SwiftUI?

Time:02-24

I have a problem. I have empty space on the top of my views, and I think that the problem is the Navigation View. View Image

I figured it out to make it work and hide that empty space with this line of code, but if I'm using this approach, my toolbar items dissapears too, and I do not want this.

    .navigationBarHidden(true)

I'll share my code below. Thanks !

TabView{
    NavigationView{
        VStack {
            MeniuriView()
            NavigationLink(isActive: $optionsActive) {
                WaitingOrderView()
                    .environmentObject(syncViewModel)
          
            } label: {
                EmptyView()
            }
        }
      
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    ToolbarButtons(numberOfProducts: menus.count) {
                        optionsActive = true
                    }
            }
                ToolbarItem(placement: .navigationBarLeading) {
                    Text(Texts.mainViewText1)
                        .font(.system(size: 24))
                        .fontWeight(.bold)
                        .padding()
                }
            }
    }
    .tabItem {
        Text(Texts.mainViewText2)
        Image(systemName: "fork.knife")
    }
}
    


struct MeniuriView: View {
    @EnvironmentObject var syncViewModel : SyncViewModel
    var body: some View {
        List  {
            ForEach(syncViewModel.menuType) { type in
                SectionView(menuType: type)
            }
        }
        .listStyle(PlainListStyle())
    }
            }

CodePudding user response:

The space is reserved for the (large) NavigationTitle. You can use

.navigationBarTitleDisplayMode(.inline)

on the NavigationView to make it small. And if its empty, it won't show.

  • Related