Created
February 5, 2026 22:29
-
-
Save simonbs/5a8fc014df2b24820bb207c8f3b713f8 to your computer and use it in GitHub Desktop.
Layout glitch with context menu in edit mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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