Scott w
Scott w

Reputation: 525

SwiftUI - Showing navigationBar caused ScrollView to jump

I have two views a scrollable ContentView which does not have a NavigationBar and an InnerView that does have a NavigationBar shown as inline. The issue that I'm having is that if I navigate to the InnerView and the back to the ContentView the ScrollView flickers when it bounces on the top of the screen. It's as though the scrollView still believes the NavigationBar is still present. Does anyone know of a way to fix this seems like a bug?

import SwiftUI


struct Example: View {
    var body: some View {
        HStack {
            Text("Example")
                .frame(maxWidth: .infinity)
                .frame(height: 245)
        }
    }
}

struct ContentView: View {
    var body: some View {
        ZStack {
            HStack {
                NavigationView {
                    ScrollView {
                        NavigationLink(destination: HStack {
                            Text("Hello")
                            .navigationBarTitle("Hello", displayMode: .inline)
                            .navigationBarHidden(false)
                        }) {
                            VStack {
                                Example()
                                Example()
                                Example()
                                Example()
                            }
                        }
                        Text("Hello, World!")
                    }.navigationBarTitle("")
                    .navigationBarHidden(true)
                }
            }
        }
        
    }
}

the bug in action

Upvotes: 2

Views: 1133

Answers (1)

stalkermv
stalkermv

Reputation: 81

Add

.navigationBarTitle("", displayMode: .inline)

or

.navigationBarTitleDisplayMode(.inline)

Upvotes: 3

Related Questions