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.
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:
This Bug is fixed in iOS 16 Beta (20A5283p)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.