NavigationView is not collapsing while having 2 List/ScrollView in HStack - SwiftUI

Viewed 86

I want to show 2 List side by side, by wrapping up both the Lists in HStack with SwiftUI framework.

BUT NavigationView is not collapsing while left side of List will scroll.

struct ContentView: View {
    var body: some View {
        NavigationView {
            HStack(spacing: 0) {
                List(0..<21) { _ in
                    Text("Hello, world!").padding()
                }
                
                List(0..<21) { _ in
                    Text("Hello, world!").padding()
                }
            }
            .navigationTitle("Home")
            //Added just to see navigation bar items
            .navigationBarItems(leading: Button("Edit") {}, trailing: Button("Done") {})
        }
    }
}

How can I collapse NavigationView while scrolling left List?

enter image description here

1 Answers

This solution may not answer your question directly but if you are okay with showing the title in a different style, give this modifier a try:

.navigationBarTitle(Text("Home"), displayMode: .inline)

Related