Ferdinand Rios
Ferdinand Rios

Reputation: 1192

SwiftUI: Tapping navigation bar in landscape list does not scroll list to top

Has anyone else come across this incorrect behavior?

  1. Create an app with the following code:
import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach (0..<100, id:\.self) { index in
                    Text("Hello, \(index)!")
                        .padding()
                }
            }
            .navigationBarTitle("Test", displayMode: .inline)
        }
    }
}
  1. Scroll the list to some item that is not initially visible.

  2. Tap on the navaigationBar Title

Result: List scrolls to top.

  1. Try the same thing with the iPhone in landscape mode.

Result: List does not scroll to top

I have filed feedback #FB9035540 on this. Just wondering if anyone else has experienced this and how they worked around it?

Upvotes: 2

Views: 673

Answers (1)

aheze
aheze

Reputation: 30446

Actually, tapping the navigation bar's title has no effect in either portrait or landscape. What you came across is the behavior that happens when you tap the status bar.

From the documentation:

The scroll-to-top gesture is a tap on the status bar. When a user makes this gesture, the system asks the scroll view closest to the status bar to scroll to the top.

The navigation bar's title and the status bar are very close together, so you probably thought it was the title that was doing the scroll.

In landscape mode, there is no status bar, so the gesture doesn't work.

Upvotes: 3

Related Questions