将 NavigationLink 重构为 LongPressGesture 的按钮

Restructure NavigationLink to Button for LongPressGesture

我正在尝试为此组列表添加 .onlongpressgesture 选项。但是,它似乎不起作用,我想它会在 Button 上起作用。 我尝试应用“.onTapGesture”和“.onLongPressGesture”,但没有效果。

有没有一种方法可以将下面的代码从 NavigationLink 转换为点击时具有相同目的地的按钮以及长按时具有附加菜单(称为“OptionsmenuView”)的按钮?

导航链接:

 VStack (spacing: 20){
                    ForEach(groups, id:\.self) { Group in
                        NavigationLink(destination: GroupView()) {
                            ZStack (alignment: .bottomLeading) {

                                Image(uiImage: (UIImage(data: Group.groupThumbnail ?? self.image) ?? UIImage(named: "defaultGroupThumbnail"))!)
                                    .resizable(capInsets: EdgeInsets())
                                    .aspectRatio(contentMode: .fill)
                                    .frame(height: 200.0, alignment: .center)
                                    .cornerRadius(22)

                                VStack (alignment: .leading) {
                                    
                                    Text("\(Group.groupTitle ?? "Untitled")")
                                        .font(.title)
                                        .fontWeight(.heavy)
                                        .multilineTextAlignment(.leading)
                                    
                                    Text("Consists of 5 Flowers")
                                }
                                .padding([.leading, .bottom], 18.0)
                                .foregroundColor(.primary)
                            }
                            .listRowBackground(Color.black)
                            
                        }
                    }
                }

选项菜单视图:

struct OptionsMenuView: View {
    var body: some View {
        
        Menu {
        Button("Cancel", role: .destructive) {
            // Do something
        }
        
        Button {
            // Do something
        } label: {
            Label("Edit", systemImage: "square.and.pencil")
        }
        
        Button {
            // Do something
        } label: {
            Label("Delete", systemImage: "trash")
        }
    } label: {
        Label("Settings", systemImage: "gearshape.fill")
    }
    }
}

我感谢任何形式的建议。提前致谢。

你不能直接使用 .contextMenu 吗?

    NavigationView {
        List (0..<10) { i in
            
            NavigationLink {
                Text("DestionationView")
            } label: {
                Text("Item \(i)")
                
            }
            .contextMenu {   // << here
                Button("Cancel", role: .destructive) {
                    // Do something
                }
                
                Button {
                    // Do something
                } label: {
                    Label("Edit", systemImage: "square.and.pencil")
                }
                
                Button {
                    // Do something
                } label: {
                    Label("Delete", systemImage: "trash")
                }
            }
        }
    }