Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 782
Easterdown Avatar asked Oct 21 '25 00:10

Easterdown


1 Answers

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

like image 107
blu-Fox Avatar answered Oct 22 '25 21:10

blu-Fox