NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

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!

   

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)

   

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 :)

   

Hacking with Swift is sponsored by Instabug

SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred. Instabug's SDK grabs all the logs they need to fix bugs, crashes and performance issues in minutes instead of days. Get screenshots, device details, network logs, repro steps, and tons of other critical insights needed to resolve issues and prioritize product backlogs straight from your dashboard. It only takes a minute to integrate!

Get started now

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

Reply to this topic…

You need to create an account or log in to reply.

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.