SwiftUI contextMenu only in dark mode

Viewed 379

Does anyone know why the contextMenu will only appear in dark mode when you put it in the view of a button:

struct ContentView: View {
    var body: some View {
        Button(action: {
        
        }) {
            Text("Button with context menu")
                .contextMenu {
                    Text("Menu Item")
                }
        }
    }
}

Tried this on iOS and iPadOS, in the simulator and on device with os versions 14.4.1, 14.4.2 & 14.5.1. I’m also almost sure, that this wasn’t always the case.

2 Answers

Probably a bug as @jnpdx said. However, if you put the contextMenu outside the Button, it works fine.

struct ContentView: View {
    var body: some View {
        Button(action: {
            print("Button pressed")
        }) {
            Text("Button with context menu")
        }
        /// outside
        .contextMenu {
            Button(action: {
                print("Menu button pressed")
            }) {
                Text("Menu Item")
            }
        }
    }
}

Result:

Light mode Dark mode
Light mode - tap button, then press and hold and tap menu button Dark mode - tap button, then press and hold and tap menu button

iOS 16

This Bug is fixed in iOS 16 Beta (20A5283p)

Related