1

I have been testing this simple SwiftUI code: It has a list in ContentView. When a cell of the list is tapped, it pushes a SecondList into the navigation stack. When this SwiftUI code was run on a real iPad with a trackpad, I used 2-finger swipe to scroll the list up and down. The list in ContentView scrolls smoothly. However, for SecondList, it may freeze randomly and thereafter not responding.

It also failed in a UIKit project, where I replaced a UINavigationView with this ContentView using UIHostingViewController.

It was testing it with iPadOS 14.5 on both Simulator and iPad Pro hardware with Magic Keyboard.

How do I fix this? Thank you.

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(0..<30, id: \.self) { index in
                    NavigationLink(
                        destination: SecondList(),
                        label: {
                            Text(String(index))
                        })
                }
            }
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

struct SecondList: View {
    var body: some View {
        List {
            ForEach(0..<30, id: \.self) { index in
                Text(String(index))
            }
        }
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Mark Lau
  • 147
  • 1
  • 9

1 Answers1

-1

Use a scrollView

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(0..<30, id: \.self) { index in
                    NavigationLink(
                        destination: SecondList(),
                        label: {
                            Text(String(index))
                        })
                }
            }
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

struct SecondList: View {
    var body: some View {
        scrollView {
            List {
                ForEach(0..<30, id: \.self) { index in
                    Text(String(index))
                }
            }
        }
    }
}
a1cd
  • 17,884
  • 4
  • 8
  • 28
  • I am afraid that your code does not work. And….how a scroll view will help in this situation? Thank you for your suggestion – Mark Lau May 01 '21 at 02:47