UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Navigation Title and ScrollView issue

Forums > SwiftUI

Xcode 12.4

I am having trouble making ScrollView behave properly when in a NavigationView which has content that doesn't go beyond the bottom edge of the screen. Here is the concrete code example:

struct ContentView: View {
    private let shortList = ["One", "Two", "Three"]
    private let longList = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]

    var body: some View {
        NavigationView {
            ScrollView(showsIndicators: false) {
                ForEach(shortList, id: \.self) { value in
                    Text(value)
                        .frame(width: 50, height: 50)
                        .background(Color.red)
                        .padding()
                }
            }
            .navigationTitle("Testing")
        }
    }
}

When I use shortList in ForEach, on iPhone 12 Pro Max, the content doesn't go beyond the screen and creates the "flickering" (idk how to call it) effect on the Navigation Title. It sort of appears and dissapears quickly when the scroll goes back to the initial position.

gif

When I use longList in ForEach, on iPhone 12 Pro Max, the content goes beyond the screen so the scroll works as expected and the Navigation Title goes from large to inline as expected.

gif

Anyone has any ideas how to solve this? Thanks!

2      

I have tried this on a real device and still get the "juddering" when push up and release quickly, however if done slowly does not happen. So probably a bug in a NavigationView, which you can send a feedback report.

Just a quick note that when user look at a list that stops before the end of the bottom of screen tend not to scroll up. The only work around is to use .navigationBarTitle("Testing", displayMode: .inline)

2      

Thank you @NigelGee. I've never submitted a feedback report before, but I will look into this.

Another "hack" I've found in the meantime is to put: .padding(.top, 0.3) on the ScrollView which seems to solve the issue. The downside of this is that you loose the blur effect when going from large to inline title. I don't know why but this bothers me more than the initial issue, but maybe somebody will find it useful :)

2      

Hi there, just in case somebody stumbles upon this issue... I ended up filing a bug report and got a response to try this in newer version of Xcode.

It's resolved in Xcode 13+

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.