0

In one of the projects I decided to comply with apple and get rid of NavigationView. In the project you had a list of buildings and after choosing a Building you had several tabs with bills, documents etc. Each of the Tabs was a different view, each with its own toolbar, buttons and functions. Here's the sample code:

import SwiftUI

struct TestView: View {
    
    var testData: [Building] = [
        Building(name: "Crystal Balls"),
        Building(name: "Geneva Towers"),
        Building(name: "Villa Navagero"),
    ]
    
    
    var body: some View {

//Here's the problem... If I change it to NavigationStack 
//all the of toolbars in tabs are gone

        NavigationView {
            List(testData) {test in
                NavigationLink {
                    TabView {
                        NavigationStack{
                            Text(test.name)
                                .navigationTitle("My Bills")
                                .navigationBarTitleDisplayMode(.inline)
                                .toolbar{
                                    ToolbarItem{
                                        Button{} label: {
                                            Image(systemName: "gear.circle")
                                        }
                                    }
                                    ToolbarItem{
                                        Button{} label: {
                                            Image(systemName: "plus.circle")
                                        }
                                    }
                                }
                        }
                                .tabItem{
                                    Label("Bills", systemImage: "doc.fill.badge.ellipsis")
                                }
                            
                            Text(test.name)
                                .tabItem{
                                    Label("Skills", systemImage: "doc.fill")
                                }
                            
                        
                    }
                    
                    
                } label: {
                    Text(test.name)
                }
            }
        }
    }
}

struct TestView_Previews: PreviewProvider {
    static var previews: some View {
        TestView()
    }
}

Having every tab as a different view and having a back button is too convenient, getting all the toolbar button to the TabView seems to "dirty" and inefficient. Maybe somebody has figured out a solution?

3
  • 1
    TabView should always be at the very top, each tab can have their own NavigationView/NavigationStack, I am sure there are a ton of little bugs you have been fighting with his setup. Apple specifies this setup in the Human Interface Guidelines. Commented Feb 8, 2023 at 19:46
  • Yes, I understand, but logic-wise it is not right. I have a lot of buildings and each building has 3-4 tabs with information, not wise-versa. So how can I start with tabs if the building is not yet chosen, that's why I went with this design Commented Feb 9, 2023 at 13:38
  • 1
    You have to create custom solutions, this design is not compatible with the standard views Commented Feb 9, 2023 at 13:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.