How do I influence SwiftUI contextMenu placements?

Viewed 183

How can I influence the placement of a contextMenu in SwiftUI? I seem to be getting the exact opposite of what I want. What I want is the context menu to be aligned with the text as indicated in the arrows in the attached photos. The image contextMenus work perfect, but the text portion is where the challenge is. I have also tried changing the alignments, but no joy...

struct ContextMenuView: View {
    var body: some View {
        HStack {
            ScrollView(.vertical, showsIndicators: false) {
                HStack {
                    VStack() {
                        Text("Test").font(.footnote)
                        Text("Test").lineLimit(30)
                    }
                    .frame(minWidth: 0, maxWidth: .infinity, alignment: .trailing)
                    .padding()
                    .background(Color.blue)
                    .cornerRadius(10)
                    .contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
                    .contextMenu() {
                        Button {
                            print("Delete")
                        } label: {
                            Label("Delete this message", systemImage: "trash")
                        }
                    }
                    Image(systemName: "person.fill")
                    .contextMenu() {
                        Button {
                            print("Send")
                        } label: {
                            Label("Send private message", systemImage: "mail")
                        }
                    }
                }.padding()
            
                HStack {
                    Image(systemName: "person.fill")
                    .contextMenu() {
                        Button {
                            print("Send")
                        } label: {
                            Label("Send private message", systemImage: "mail")
                        }
                    }
                    VStack() {
                        Text("Test").font(.footnote)
                        Text("Test").lineLimit(30)
                    }
                    .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
                    .padding()
                    .background(Color.blue)
                    .cornerRadius(10)
                    .contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
                    .contextMenu() {
                        Button {
                            print("Delete")
                        } label: {
                            Label("Delete this message", systemImage: "trash")
                        }
                    }
                }.padding()
            }
        }
    }
}

enter image description here enter image description here

enter image description here

0 Answers
Related