2

I have created one sidebar with NavigationView, which by default appends to the left of the landscape view of application. However I wanted to have another on the right side.

NavigationView {
  List {
    Label("Pencil", systemImage: "pencil")
    Label("Paint", systemImage: "paintbrush.fill")
    Label("Erase", systemImage: "quote.opening")
      Label("Cutter", systemImage: "scissors")
      Label("Eyedropper", systemImage: "eyedropper.halffull")
      Label("Draw Line", systemImage: "line.diagonal")

  }
  .listStyle(SidebarListStyle())
}
    

Image of preview screen

burnsi
  • 6,194
  • 13
  • 17
  • 27
  • 1
    SwiftUI does not support that - you have to create something like that manually. – Asperi Jul 03 '22 at 10:40
  • Can I use UIKit to bridge with SwiftUI, and additionally with application going to get more bigger would it be right to use SwiftUI? – Varun Sharma Jul 03 '22 at 10:42
  • 1
    Using `SwiftUI` & `UIKit` inside the same app is totally fine. Have a look at `UIViewRepresentable`, `UIViewControllerRepresentable` & `UIHostingController`. – Timmy Jul 03 '22 at 11:52

1 Answers1

1

Here's a simple working example made with SwiftUI:

struct ContentView: View {
    var body: some View {
        NavigationView{
            
            TagView()
            
            Text("Default second View")
            Text("Default Third View")
        }
    }
}


struct TagView: View {
    let tags = ["Apple", "Google"]
    var body: some View {
        List{
            ForEach(tags, id: \.self) { name in
                NavigationLink {
                    ProductView(tag: name)
                } label: {
                    Text(name)
                }

            }
        }
    }
}


struct ProductView: View {
    var tag: String
    var products: [String] {
        if tag == "Apple" {
            return ["iPhone", "iPad", "MacBook"]
        } else {
            return ["resuable stuff"]
        }
    }
    var body: some View {
        List{
            ForEach(products, id: \.self) { name in
                NavigationLink {
                    DetailsView()
                } label: {
                    Text(name)
                }

            }
        }
    }
}


struct DetailsView: View {
    var body: some View {
        Text("Detailed explanation about product")
    }
}

enter image description here

Seungjun
  • 874
  • 9
  • 21