Last active
April 5, 2021 14:06
-
-
Save krzysztofzablocki/9cdb3ffa14f4ab92a8b2d624efbbbfa3 to your computer and use it in GitHub Desktop.
Why isn't last delete refreshing the list? Mac example
This file contains 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
@main | |
struct ListBugApp: App { | |
var body: some Scene { | |
WindowGroup { | |
NavigationView { // comment out navigation view and list works | |
ContentView() | |
Text("Detail") | |
} | |
} | |
} | |
} | |
struct ContentView: View { | |
@State | |
var items = ["Delete", "All", "Items"] | |
@State | |
var selection: String? | |
var body: some View { | |
List(selection: $selection) { | |
ForEach(items, id: \.self) { item in | |
Text(item) | |
.tag(item) | |
.contextMenu { | |
Button(action: { | |
if let idx = self.items.firstIndex(of: item) { | |
self.items.remove(at: idx) | |
} else { | |
print("Item doesn't exist") | |
} | |
}){ | |
Text("Delete") | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like a bug 😞
The simplest workaround I found to be working is to add an extra view to the
List
and hide it: