Skip to content

Instantly share code, notes, and snippets.

@simonbs
Created February 5, 2026 22:29
Show Gist options
  • Select an option

  • Save simonbs/5a8fc014df2b24820bb207c8f3b713f8 to your computer and use it in GitHub Desktop.

Select an option

Save simonbs/5a8fc014df2b24820bb207c8f3b713f8 to your computer and use it in GitHub Desktop.
Layout glitch with context menu in edit mode
import SwiftUI
struct Item: Identifiable {
let id: String
let title: String
init(title: String) {
self.id = UUID().uuidString
self.title = title
}
}
struct ContentView: View {
@State private var items = [
Item(title: "John"), Item(title: "Jane"),
Item(title: "James"), Item(title: "Janet")
]
var body: some View {
NavigationStack {
List {
ForEach(items) { item in
Text(item.title)
.contextMenu {
Button {
} label: {
Text("Action 1")
}
Button {
} label: {
Text("Action 2")
}
}
}
.onDelete { _ in }
.onMove { _, _ in }
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
EditButton()
.fontWeight(.medium)
}
}
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment