2

I have a LazyVGrid with items in it, I don't have any padding on the items because I prefer to let the layout of the LazyVGrid manage the spacing between cells. but when I open the context menu on the item it displays the item as it is with no padding.

enter image description here

how can I tell the context menu to show the preview with added padding around the cell?

Halpo
  • 2,982
  • 3
  • 25
  • 54

1 Answers1

1

In iOS 16 and higher, the contextMenu modifier takes a preview argument that is of type some View.

This view could have padding, or a customised Image. To get padding to work, you might need to wrap the views and padding in a parent view at the top of the hierarchy.

You haven’t shared your code so I can’t give you an example in your context, but it could look like this:

struct MyView: View {
    var body: some View {
        Text("Example")
            .contextMenu {
                // Context menu stuff
            } preview: {
                // Preview here
            }
    }
}
Chris
  • 4,009
  • 3
  • 21
  • 52