Fix accent color circles not showing on iOS 15

This commit is contained in:
Shadowfacts 2023-02-02 23:36:47 -05:00
parent af8a9faaeb
commit 37847a2f9f
1 changed files with 18 additions and 3 deletions

View File

@ -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)