New icons + rework icon selector

This commit is contained in:
Thomas Ricouard 2022-12-31 14:01:00 +01:00
parent 51e86190ef
commit 224b1b0693
26 changed files with 239 additions and 35 deletions

View file

@ -2,46 +2,40 @@ import SwiftUI
import DesignSystem import DesignSystem
struct IconSelectorView: View { struct IconSelectorView: View {
enum Icon: String, CaseIterable, Identifiable { enum Icon: Int, CaseIterable, Identifiable {
var id: String { var id: String {
self.rawValue "\(rawValue)"
} }
case primary = "AppIcon" init(string: String) {
case alternate1 = "AppIconAlternate1" if string == Icon.primary.appIconName {
case alternate2 = "AppIconAlternate2" self = .primary
case alternate3 = "AppIconAlternate3" } else {
case alternate4 = "AppIconAlternate4" self = .init(rawValue: Int(String(string.last!))!)!
case alternate5 = "AppIconAlternate5" }
case alternate6 = "AppIconAlternate6" }
case alternate7 = "AppIconAlternate7"
case alternate8 = "AppIconAlternate8" case primary = 0
case alternate9 = "AppIconAlternate9" case alt1, alt2, alt3, alt4, alt5, alt6, alt7, alt8
case alternate10 = "AppIconAlternate10" case alt9, alt10, alt11, alt12, alt13, alt14
case alternate11 = "AppIconAlternate11" case alt15, alt16, alt17, alt18
case alternate12 = "AppIconAlternate12"
var appIconName: String {
switch self {
case .primary:
return "AppIcon"
default:
return "AppIconAlternate\(rawValue)"
}
}
var iconName: String { var iconName: String {
switch self { "icon\(rawValue)"
case .primary: return "icon0"
case .alternate1: return "icon1"
case .alternate2: return "icon2"
case .alternate3: return "icon3"
case .alternate4: return "icon4"
case .alternate5: return "icon5"
case .alternate6: return "icon6"
case .alternate7: return "icon7"
case .alternate8: return "icon8"
case .alternate9: return "icon9"
case .alternate10: return "icon10"
case .alternate11: return "icon11"
case .alternate12: return "icon12"
}
} }
} }
@EnvironmentObject private var theme: Theme @EnvironmentObject private var theme: Theme
@State private var currentIcon = UIApplication.shared.alternateIconName ?? Icon.primary.rawValue @State private var currentIcon = UIApplication.shared.alternateIconName ?? Icon.primary.appIconName
private let columns = [GridItem(.adaptive(minimum: 125, maximum: 1024))] private let columns = [GridItem(.adaptive(minimum: 125, maximum: 1024))]
@ -51,11 +45,11 @@ struct IconSelectorView: View {
LazyVGrid(columns: columns, spacing: 6) { LazyVGrid(columns: columns, spacing: 6) {
ForEach(Icon.allCases) { icon in ForEach(Icon.allCases) { icon in
Button { Button {
currentIcon = icon.rawValue currentIcon = icon.appIconName
if icon.rawValue == Icon.primary.rawValue { if icon.rawValue == Icon.primary.rawValue {
UIApplication.shared.setAlternateIconName(nil) UIApplication.shared.setAlternateIconName(nil)
} else { } else {
UIApplication.shared.setAlternateIconName(icon.rawValue) UIApplication.shared.setAlternateIconName(icon.appIconName)
} }
} label: { } label: {
ZStack(alignment: .bottomTrailing) { ZStack(alignment: .bottomTrailing) {
@ -65,7 +59,7 @@ struct IconSelectorView: View {
.frame(minHeight: 125, maxHeight: 1024) .frame(minHeight: 125, maxHeight: 1024)
.cornerRadius(6) .cornerRadius(6)
.shadow(radius: 3) .shadow(radius: 3)
if icon.rawValue == currentIcon { if icon.appIconName == currentIcon {
Image(systemName: "checkmark.seal.fill") Image(systemName: "checkmark.seal.fill")
.padding(4) .padding(4)
.tint(.green) .tint(.green)

View file

@ -102,7 +102,7 @@ struct SettingsTabs: View {
Label { Label {
Text("Icon selector") Text("Icon selector")
} icon: { } icon: {
if let icon = IconSelectorView.Icon(rawValue: UIApplication.shared.alternateIconName ?? "AppIcon") { if let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon") {
Image(uiImage: .init(named: icon.iconName)!) Image(uiImage: .init(named: icon.iconName)!)
.resizable() .resizable()
.frame(width: 25, height: 25) .frame(width: 25, height: 25)

View file

@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "icon13.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 KiB

View file

@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "icon14.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 KiB

View file

@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "icon15.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

View file

@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "icon16.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 KiB

View file

@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "icon17.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

View file

@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "icon18.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "icon13.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 KiB

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "icon14.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 KiB

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "icon15.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "icon16.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 KiB

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "icon17.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "icon18.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB