Easterdown
Easterdown

Reputation: 43

IOS 17 NavigationStack bug? - EditButton does not perform as expected in a NavigationStack

This performs as expected, the selection triggers right away

struct ListSelectionTest: View {
  @State var selection: Set<String> = []
  let strings = ["One", "Two", "Three"]
  var body: some View {
    VStack {
      EditButton()
      List(selection: $selection) {
        ForEach(strings, id: \.self) { string in
          Text(string).tag(string)
        }
      }
    }
    .padding()
  }
}

#Preview {
    ListSelectionTest()
}

The problem appears when the List is wrapped in NavigationStack. This does not work:

struct ListSelectionTest: View {
  @State var selection: Set<String> = []
  let strings = ["One", "Two", "Three"]
  var body: some View {
    NavigationStack {
      VStack {
        EditButton()
        List(selection: $selection) {
          ForEach(strings, id: \.self) { string in
            Text(string).tag(string)
          }
        }
      }
      .padding()
    }
  }
}

#Preview {
    ListSelectionTest()
}

When I updated to IOS 17 I found that my EditButton, wrapped in a NavigationStack, won't work the first time you click it. It will work first time if you have already selected a row in the list. But that shouldn't be needed. When I remove the NavigationStack, EditButton works first time as expected, whether there is a selected row in the list or not. On IOS 16.4 EditButton works first time as expected in a NavigationStack, whether there is a selected row in the list or not. I've submitted this to Apple FB13201571. Any thoughts for a workaround?

Upvotes: 4

Views: 331

Answers (1)

blu-Fox
blu-Fox

Reputation: 656

This was confirmed by Apple as a SwiftUI bug and was resolved for iOS17.2+.

Upvotes: 3

Related Questions