From 37847a2f9fb60317114cf18aaf77fa900acc4e95 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 2 Feb 2023 23:36:47 -0500 Subject: [PATCH] Fix accent color circles not showing on iOS 15 --- .../Preferences/AppearancePrefsView.swift | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Preferences/AppearancePrefsView.swift b/Tusker/Screens/Preferences/AppearancePrefsView.swift index b0780279..be3ac44e 100644 --- a/Tusker/Screens/Preferences/AppearancePrefsView.swift +++ b/Tusker/Screens/Preferences/AppearancePrefsView.swift @@ -28,6 +28,21 @@ struct AppearancePrefsView : View { }) { Preferences.shared.avatarStyle = $0 ? .circle : .roundRect } + + private let accentColorsAndImages: [(Preferences.AccentColor, UIImage?)] = Preferences.AccentColor.allCases.map { color in + var image: UIImage? + if let color = color.color { + if #available(iOS 16.0, *) { + image = UIImage(systemName: "circle.fill")!.withTintColor(color, renderingMode: .alwaysTemplate).withRenderingMode(.alwaysOriginal) + } else { + image = UIGraphicsImageRenderer(size: CGSize(width: 20, height: 20)).image { context in + color.setFill() + context.cgContext.fillEllipse(in: CGRect(x: 0, y: 0, width: 20, height: 20)) + } + } + } + return (color, image) + } var body: some View { List { @@ -48,12 +63,12 @@ struct AppearancePrefsView : View { } Picker(selection: accentColor, label: Text("Accent Color")) { - ForEach(Preferences.AccentColor.allCases, id: \.rawValue) { color in + ForEach(accentColorsAndImages, id: \.0.rawValue) { (color, image) in HStack { Text(color.name) - if let color = color.color { + if let image { Spacer() - Image(uiImage: UIImage(systemName: "circle.fill")!.withTintColor(color, renderingMode: .alwaysTemplate).withRenderingMode(.alwaysOriginal)) + Image(uiImage: image) } } .tag(color)