Issue with Menu title and decreased opacity

Viewed 143

I want to use the new Menu with SwiftUI but unfortunately there is one issue which I can't solve. After selecting one value of the Menu the Menutitle looks like so:

enter image description here

However I don't want the title to decrease it's opacity. How can I achieve this?

Here is my code:

struct ContentView: View {
    @State private var selectionVariable = 0
    
    let sampleDict = [0: "Sample Title 1", 1: "Sample Title 2"]
    
    var body: some View {
        Menu {
            Picker(selection: $selectionVariable, label: Text("")) {
                ForEach(sampleDict.sorted(by: <), id: \.key) { base, name in
                    Text(name)
                }
            }
        }
        label: {
            Text("Eingaben im \(sampleDict[selectionVariable] ?? "")")
        }
    }
}
2 Answers

It looks like a bug.

A possible workaround is to remove Picker animations using .animation(nil):

struct ContentView: View {
    @State private var selectionVariable = 0

    let sampleDict = [0: "Sample Title 1", 1: "Sample Title 2"]

    var body: some View {
        Menu {
            Picker(selection: $selectionVariable, label: Text("")) {
                ForEach(sampleDict.sorted(by: <), id: \.key) { base, name in
                    Text(name)
                }
            }
        }
        label: {
            Text("Eingaben im \(sampleDict[selectionVariable] ?? "")")
        }
        .animation(nil) // add here
    }
}

I'd say it looks like a bug, anyway worth submitting feedback to Apple.

Here is tested workaround (Xcode 12.1 / iOS 14.1)

    label: {
        Text("Eingaben im \(sampleDict[selectionVariable] ?? "")")
                .id(selectionVariable)    // << this one !!
    }
Related