.swipeActions 中的 .confirmationDialog 不起作用,iOS 15

.confirmationDialog inside of .swipeActions does not work, iOS 15

关于iOS15,Xcode13;我想知道这是一个错误、未正确实施还是计划中的非功能性功能...

对于具有调用 .confirmationDialog.swipeActions 的列表,确认对话框不会显示。

参见示例:

import SwiftUI

struct ContentView: View {
    
    @State private var confirmDelete = false
    
    var body: some View {
        NavigationView {
            List{
                ForEach(1..<10) {_ in
                    Cell()
                }

                .swipeActions(edge: .trailing) {
                    Button(role: .destructive) {
                        confirmDelete.toggle()
                    } label: {
                        Label("Delete", systemImage: "trash")
                    }

                    .confirmationDialog("Remove this?", isPresented: $confirmDelete) {
                        Button(role: .destructive) {
                            print("Removed!")
                        } label: {
                            Text("Yes, Remove this")
                        }
                    }
                }
            }
        }
    }
}

struct Cell: View {
    var body: some View {
        Text("Hello")
            .padding()
    }
}

配置错误:

需要将视图修饰符 .confirmationDialog 添加到 之外的视图 .swipeActions视图修饰符。正确配置后它会工作,如下所示:

import SwiftUI

struct ContentView: View {
    
    @State private var confirmDelete = false
    
    var body: some View {
        NavigationView {
            List{
                ForEach(1..<10) {_ in
                    Cell()
                }
                .swipeActions(edge: .trailing) {
                    Button(role: .destructive) {
                        confirmDelete.toggle()
                    } label: {
                        Label("Delete", systemImage: "trash")
                    }
                }
                //move outside the scope of the .swipeActions view modifier:
                .confirmationDialog("Remove this?", isPresented: $confirmDelete) {
                    Button(role: .destructive) {
                        print("Removed!")
                    } label: {
                        Text("Yes, Remove this")
                    }
                }
            }
        }
    }
}

struct Cell: View {
    var body: some View {
        Text("Hello")
            .padding()
    }
}