0

I am trying to use the new Pull to Refresh feature in the latest version of SWiftUI which requires a List. Enclosing the VStack in a List causes the NavigationLink to work only once. Below is a simple version of the code without the Pull To Refresh part.

There is a question that was asked 68144891 on stackoverflow and there was a refrence to a known issue link which takes you to a page not found (https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-15-beta-release-notes)

Steps o reproduce

  1. Tap "Press Me 1" or one of the items
  2. Tap "Show Details"
  3. Tap Back at the top
  4. Tap "Press Me" again will not navigate to the next screen. A grey screen blocks when you tap

The app works without the VStack

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                VStack { // commenting VStack works
                    Text("Options").font(.largeTitle).bold()
                    ForEach(1..<5, id:\.self) { counter in
                        NavigationLink(destination: SubView(counter: counter)) {
                            Text("Press Me \(counter)").font(.headline)
                        }
                        .buttonStyle(PlainButtonStyle())
                    }
                }
            }.listStyle(.grouped)
        }
    }
}

struct SubView: View {
    var counter: Int
    @State private var showDetails = false
    var body: some View {
        VStack(alignment: .leading) {
            Button("Show details") {
                showDetails.toggle()
            }
            
            if showDetails {
                Text("Clicked")
                    .font(.largeTitle)
            }
        }
    }
}

Any help appreciated

Thanks much!

RXP
  • 517
  • 4
  • 18
  • And why you want the "vstack" inside your list ? th "vstack" is putting the whole list to one element and thats not what you want. – Osman Oct 05 '21 at 22:39
  • I actually have a LazyVStsck with pinned section headers in the actual app. Just for the example I used a VStack to illustrate the bug. – RXP Oct 06 '21 at 00:10
  • By adding `VStack` as root of `List` you made all content as **one row** - I don't think this what you really wanted to do, so just remove `VStack` from the top. And by the way List already loads rows in lazy way. – Asperi Oct 06 '21 at 04:48

1 Answers1

0

... follow-up to my comment

I assume you wanted this

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                Section(Text("Options").font(.largeTitle).bold()) {
                    ForEach(1..<5, id:\.self) { counter in
                        NavigationLink(destination: SubView(counter: counter)) {
                            Text("Press Me \(counter)").font(.headline)
                        }
                        .buttonStyle(PlainButtonStyle())
                    }
                }
            }.listStyle(.grouped)
        }
    }
}
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • Asperi, Thanks for your response. This works when there are no pinned sections. In my actual App I have pinned sections and graphs that are part of the LazyVStack. I am trying to implement the Pull to refresh feature introduced in the IOS15 which requires me to use List. Hence the problem. Also, I am using several subviews that already use VStack which will be hard to re-architect. Do you think there is any other alternative? – RXP Oct 06 '21 at 05:24