UPDATE: I believe I've found a fix.
The issue was partly that the buttons I want in .swipeActions(edge: .leading) { ... } are in a separate View struct called LeftSwipeButtons, and the ones going into .swipeActions(edge: .trailing) { ... } are in their own struct called RightSwipeButtons. This means passing Binding vars into them so that the ItemRow can use them, and send their value back to the view that's got my List in it, i.e.:
struct ItemRow: View {
@Binding var x: Bool
@Binding var y: Bool
var body: some View {
...
}
.swipeActions(edge: .leading) {
LeftSwipeButtons(x: $x, y: $y ... )
}
.swipeActions(edge: .trailing) {
RightSwipeButtons(x: $x, y: $y ... ) // Has .confirmationDialog inside
// But also exhibits the issue if I put .confirmationDialog here
}
.contextMenu {
ContextMenu( ... ) // Has .confirmationDialog inside
// But also exhibits the issue if I put .confirmationDialog here
}
}
Adding .confirmationDialog inside RightSwipeButtons or inside .swipeActions didn't work because the button disappeared.
It seems that the fix for this was to move all that code back into the ItemRow itself and add .confirmationDialog onto the end.
Same problem with the context menu. I couldn't add .confirmationDialog inside my ContextMenu struct, or add it inside .contextMenu.
Once I moved all the code back into ItemRow it all worked (though ItemRow is now about 450 lines...).
struct ItemRow: View {
var body: some View {
...
}
.swipeActions(edge: .leading) {
if(a == 1) { ... }. // etc.
}
.swipeActions(edge: .trailing) {
if(b == 2) { ... }. // etc.
}
.contextMenu {
...
}
.confirmationDialog { ... }
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: