In SwiftUI, I would like to use a background color for my view while also setting navigationViewStyle to .stack
, to force a single-column stack navigation Plus-sized devices.
var body: some View { TabView { NavigationView { ScrollView { ForEach(0..<100) { _ in Text("Bubble") .padding() } .frame(maxWidth: .infinity) } .navigationTitle("Foam") // .background(Color.yellow) // I can do this … } // .navigationViewStyle(.stack) // … or this, but not both! .tabItem { Label("Beer", systemImage: "swift") } } }
However, when I do both, the navigation bar won't collapse when I scroll down. Also both the navigation bar and tab bar appear without background.
When I only set the background, but leave out the line that sets the navigationViewStyle, everything looks fine in portrait mode, or smaller devices. But on a Plus-size device in landscape, it looks like this:
So I guess I really can't do this without setting the navigationViewStyle.
What can I do to fix this? Is this a bug that should be fixed by Apple? All help is greatly appreciated.