Skip to content

fix: don't use removable Section header in NavigationSplit#224

Merged
eagleoflqj merged 1 commit intomasterfrom
group
Feb 7, 2025
Merged

fix: don't use removable Section header in NavigationSplit#224
eagleoflqj merged 1 commit intomasterfrom
group

Conversation

@eagleoflqj
Copy link
Member

Async operations on view model doesn't eliminate the bug. It only makes it intermittent.
Minimal reproducible view on macOS:

import SwiftUI

struct HeaderView: View {
  let onDelete: () -> Void

  var body: some View {
    Text("Header")
      .contextMenu {
        Button {
          onDelete()
        } label: {
          Text("Delete")
        }
      }
  }
}

struct ContentView: View {
  @State private var list = [String]()

  var body: some View {
    NavigationSplitView {
      List {
        ForEach(list, id: \.self) { item in
          Section(header: HeaderView(onDelete: {
            list.removeAll { $0 == item }
          })) {
            Text(item)
          }
        }
      }
    } detail: {
      Text("Detail")
    }.onAppear() {
      list = ["Item 1", "Item 2", "Item 3"]
    }
  }
}

Without NavigationSplit or without header the crash won't happen. Absolutely a bug in SwiftUI.

@github-actions
Copy link

github-actions bot commented Feb 7, 2025

arm64 comparison

No difference.

x86_64 comparison

No difference.

@eagleoflqj eagleoflqj merged commit 697b17c into master Feb 7, 2025
7 checks passed
@eagleoflqj eagleoflqj deleted the group branch February 7, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant