Here is my code simplified.
struct TileView: View {
@Binding var editMode: EditMode
var columns = [GridItem(.adaptive(minimum: UIScreen.main.bounds.width / 4))]
var body: some View {
LazyVGrid(columns: columns, spacing: 16) {
ForEach(0 ..< 5, id: \.self) { num in
ZStack(alignment: .topLeading) {
GroupBox(label: Text("Label")) {
Text("Content")
}
.contextMenu {
Button {
} label: {
Label("Delete", systemImage: "trash")
}
}
// this is the work around for the delete action
if editMode == .active {
Button {
} label: {
Label("Delete", systemImage: "minus.circle.fill")
.imageScale(.large)
.foregroundColor(Color(.systemRed))
.backgroundColor(Color(.systemFill)
.clipShape(Circle())
.labelStyle(IconOnlyLabelStyle())
.offset(x: -10, y: -10)
}
}
}
.padding(.horizontal, 4)
}
}
}
.padding(.horizontal)
}
}
Is there any way I can add an .onMove or .onDelete modifier to the ForEach and have those actions work when editing, or something else similar (maybe implementing a List to make it work)?
If not, is there a workaround for the move action (since I already have a delete action workaround)?
Thanks in advance for any solutions.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
Is there any way to add destructive actions (such as a delete button in red) or separators to the new Menu in iOS and iPadOS as shown in the Build/Design with iOS pickers, menus and actions talks?
There's no way that I know of with .contextMenu and I was wondering if there was a way or a workaround.