Skip to content

Commit 6df68ff

Browse files
committed
home: confirm delete vm with swipe
Fixes #3086
1 parent 24c8507 commit 6df68ff

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

Platform/Shared/VMConfirmActionModifier.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ enum ConfirmAction: Identifiable, Equatable {
4949

5050
struct VMConfirmActionModifier: ViewModifier {
5151
@Binding var confirmAction: ConfirmAction?
52+
var workaroundSwipeBug: Bool = false
5253
let onConfirm: (ConfirmAction) -> Void
5354
@EnvironmentObject private var data: UTMData
5455
@State private var isPresented: Bool = false
5556

5657
@ViewBuilder func body(content: Content) -> some View {
57-
if #available(iOS 15, macOS 12, *) {
58+
// SwiftUI bug: swipe + confirmationDialog is broken
59+
if !workaroundSwipeBug, #available(iOS 15, macOS 12, *) {
5860
newBody(content: content)
5961
} else {
6062
oldBody(content: content)

Platform/Shared/VMNavigationListView.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import TipKit
1919

2020
struct VMNavigationListView: View {
2121
@EnvironmentObject private var data: UTMData
22-
22+
@State private var confirmAction: ConfirmAction?
23+
2324
var body: some View {
2425
if #available(iOS 16, macOS 13, *) {
2526
CompatibleNavigationSplitView {
@@ -57,6 +58,13 @@ struct VMNavigationListView: View {
5758
VMCardView(vm: vm)
5859
.modifier(VMContextMenuModifier(vm: vm))
5960
.tag(vm)
61+
.swipeActions {
62+
Button(role: .destructive) {
63+
confirmAction = .confirmDeleteVM(vm: vm)
64+
} label: {
65+
Label("Delete", systemImage: "trash")
66+
}
67+
}
6068
} else {
6169
NavigationLink(
6270
destination: VMDetailsView(vm: vm),
@@ -67,9 +75,7 @@ struct VMNavigationListView: View {
6775
}
6876
}
6977
}.onMove(perform: move)
70-
#if !WITH_REMOTE // FIXME: implement remote feature
71-
.onDelete(perform: delete)
72-
#endif
78+
.modifier(VMConfirmActionModifier(confirmAction: $confirmAction, workaroundSwipeBug: true, onConfirm: { _ in }))
7379

7480
if data.pendingVMs.count > 0 {
7581
Section(header: Text("Pending")) {

0 commit comments

Comments
 (0)