App freezes when using a SwiftUI Picker with pickerStyle(.segment), Images with .symbolRenderingMode(.palette) and try to show a sheet.
import SwiftUI
enum Sample: String, CaseIterable, Identifiable {
case aaa, bbb, ccc, ddd
var id: Self { self }
var image: Image {
switch self {
case .aaa: Image(systemName: "square.stack.3d.up.fill")
case .bbb: Image(systemName: "square.and.arrow.up")
case .ccc: Image(systemName: "square.and.arrow.up.fill")
case .ddd: Image(systemName: "square.and.arrow.down")
}
}
}
struct PickerBug: View {
@State private var selected: Sample = .aaa
@State var showSheet = false
var body: some View {
List {
Section {
VStack {
Picker("Qqq", selection: $selected) {
ForEach(Sample.allCases) { sample in
sample.image
// .symbolRenderingMode(.palette)
.foregroundStyle(.black)
}
}
.pickerStyle(.segmented)
}
}
Text("Aaa")
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button {
showSheet.toggle()
} label: {
Text("A")
}
}
}
.sheet(isPresented: $showSheet) {
Text("Aaaa")
}
}
}
#Preview {
NavigationStack {
PickerBug()
}
}
Uncomment .symbolRenderingMode(.palette)
show the picker and the app freezes.
Xcode, Preview and Simulator, i could not test on a real device.