'SwiftUI: Problem with Picker inside ContextMenu of NavigationBarItem
I'm trying to use Picker on .contextMenu of navigationBarItems. However, the behavior is not as I would expect and I can't tell if this is Apple bug or if I'm doing something wrong (XCode 13.4).
After the user selects an item from the dropdown, the variable value do change but reopening the context menu, the wrong item is marked as "selected".
I've created the most basic demo to illustrate it. Same behavior on real device (iPhone 11 / iOS 15.4.1).
struct ContentView: View {
@State private var isAutoRefresh = true
var body: some View {
NavigationView {
Text("Auto refresh is: \(String(isAutoRefresh))")
.navigationBarTitle("Demo")
.navigationBarItems(
trailing:
Button(action: {}, label: {
Image(systemName: "arrow.clockwise")
})
.contextMenu {
Picker(selection: self.$isAutoRefresh, label: Text("")) {
Text("Manual refresh").tag(false)
Text("Auto refresh").tag(true)
}
.pickerStyle(InlinePickerStyle())
}
)
}
}
}
Is this a bug? Is there any workaround I can use?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

