SwiftUI Picker animation bug after selection

Viewed 379

When I select something from my picker, the animation / highlight stays there, and doesn't disappear.

Problem

 Picker(selection: $selectedFrameworkIndex, label:             HStack {
                            Image(systemName: "location.fill")
                            Text("Indulás innen:")
                            
                        }) {
                            ForEach(0 ..< stations.count, id: \.self) {
                                if direction == stations[$0].direction {
                                    Text(stations[$0].name)
                                    
                                }
                            }
                            
                            
                        }

@State private var selectedFrameworkIndex = 0
1 Answers

It looks like another iOS 14.2 defect.

Try the following workaround:

Picker(selection: $selectedFrameworkIndex, label: 
  HStack {

    Image(systemName: "location.fill")
    Text("Indulás innen:")
    
  }) {
    ForEach(0 ..< stations.count, id: \.self) {
        if direction == stations[$0].direction {
            Text(stations[$0].name)
            
        }
    }
}.id(selectedFrameworkIndex)       // << here !!
Related