Context menu previews are ignoring the parent's scaleEffect() modifier

If you add the .scaleEffect() modifier to a parent view inside of which there are children with contextMenu()-s, the context menu preview unfortunately keeps the original, unscaled size of the child view. This results in a very weird, glitchy user experience.

Unfortunately, providing a custom preview that is scaled up also does not help, since even though it is the right size, it gets cropped to the unscaled size of the child view.

Adding scaleEffect() to each child element individually (BEFORE the contextMenu() modifier!) does make the problem disappear. However, I would like to avoid this, since my use case is zooming into a complex graph with context menus on its nodes, and having to recalculate the position of each node manually seems to perform much worse than delegating that work to scaleEffect().

Tested on iOS 18.2 (device + emulator)

Is there a workaround?

Here is a minimal working example that demonstrates the problem:

struct ContentView: View {
    var body: some View {
        VStack(spacing: 20) {
            Rectangle()
                .frame(width: 100, height: 100)
                .contextMenu {
                    Button("Test") {}
                    Button("Test") {}
                }
            Rectangle()
                .frame(width: 100, height: 100)
                .contextMenu {
                    Button("Test") {}
                    Button("Test") {}
                }
        }
        .scaleEffect(1.5)
    }
}

Screenshot (problem: The two squares are the same size. However, the long-tapped upper square got shrunk down before the context menu got displayed.)

@apart from the workaround you described, You can use the contentShape modifier before the contextMenu modifier to affect the shape of the preview

If you'd like us to consider adding the more fine grain control over the default preview, please file an enhancement request using Feedback Assistant. Once you file the request, please post the FB number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

Thank you, I will file a feedback report about this.

Is there, by the way, any way to disable the context menu preview and the preceding press animation (that in my case, shrinks the long pressed view to the wrong (unscaled) size) altogether?

Context menu previews are ignoring the parent's scaleEffect() modifier
 
 
Q