Cannot configure contentShape for final preview of .contextMenu(menuItems: , preview: )

Without using a custom preview, you can set .contentShape(RoundedRectangle(cornerRadius: 30)) so that in the "zoomed in" preview of the contextMenu you can have a custom cornerRadius. However, this does not work if you create a custom preview, because then the ContentShape gets applied only to the LIFT PREVIEW, and not to the FINAL PREVIEW state. Heres a sample code - I'd love some support! :)

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Rectangle()
                .fill(Color.blue)
                .frame(width: 300, height: 300)
            
                .cornerRadius(30)
                .contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 30))
                .contextMenu {
                    Button("Hello") {}
                    Button("Goofy") {}
                } preview: {
                    Rectangle()
                        .fill(Color.blue)
                        .frame(width: 300, height: 300)
                        .cornerRadius(30)
                        //.contentShape(RoundedRectangle(cornerRadius: 30))
                        //.contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 30))
                }

            Text("contextMenu item with large cornerRadius is not working as expected... No way to set contentShape to custom corner radius for final preview - not the lift preview")
        }
    }
        
}
Answered by DTS Engineer in 839101022

@ileb Could you try using .clipShape(.rect(cornerRadius:).inset(by:)) for your custom preview

Accepted Answer

@ileb Could you try using .clipShape(.rect(cornerRadius:).inset(by:)) for your custom preview

Cannot configure contentShape for final preview of .contextMenu(menuItems: , preview: )
 
 
Q