2022-12-04 09:50:25 +01:00
|
|
|
import SwiftUI
|
2022-12-29 10:39:34 +01:00
|
|
|
import DesignSystem
|
2022-12-04 09:50:25 +01:00
|
|
|
|
|
|
|
struct IconSelectorView: View {
|
|
|
|
enum Icon: String, CaseIterable, Identifiable {
|
|
|
|
var id: String {
|
|
|
|
self.rawValue
|
|
|
|
}
|
|
|
|
|
2022-12-27 21:35:41 +01:00
|
|
|
case primary = "AppIcon"
|
2022-12-04 09:50:25 +01:00
|
|
|
case alternate1 = "AppIconAlternate1"
|
|
|
|
case alternate2 = "AppIconAlternate2"
|
|
|
|
case alternate3 = "AppIconAlternate3"
|
|
|
|
case alternate4 = "AppIconAlternate4"
|
2022-12-27 22:01:40 +01:00
|
|
|
case alternate5 = "AppIconAlternate5"
|
|
|
|
case alternate6 = "AppIconAlternate6"
|
|
|
|
case alternate7 = "AppIconAlternate7"
|
|
|
|
case alternate8 = "AppIconAlternate8"
|
2022-12-28 11:34:31 +01:00
|
|
|
case alternate9 = "AppIconAlternate9"
|
|
|
|
case alternate10 = "AppIconAlternate10"
|
|
|
|
case alternate11 = "AppIconAlternate11"
|
|
|
|
case alternate12 = "AppIconAlternate12"
|
2022-12-27 21:35:41 +01:00
|
|
|
|
|
|
|
var iconName: String {
|
|
|
|
switch self {
|
|
|
|
case .primary: return "icon0"
|
|
|
|
case .alternate1: return "icon1"
|
|
|
|
case .alternate2: return "icon2"
|
|
|
|
case .alternate3: return "icon3"
|
|
|
|
case .alternate4: return "icon4"
|
2022-12-27 22:01:40 +01:00
|
|
|
case .alternate5: return "icon5"
|
|
|
|
case .alternate6: return "icon6"
|
|
|
|
case .alternate7: return "icon7"
|
|
|
|
case .alternate8: return "icon8"
|
2022-12-28 11:34:31 +01:00
|
|
|
case .alternate9: return "icon9"
|
|
|
|
case .alternate10: return "icon10"
|
|
|
|
case .alternate11: return "icon11"
|
|
|
|
case .alternate12: return "icon12"
|
2022-12-27 21:35:41 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:39:34 +01:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2022-12-04 09:50:25 +01:00
|
|
|
@State private var currentIcon = UIApplication.shared.alternateIconName ?? Icon.primary.rawValue
|
|
|
|
|
|
|
|
private let columns = [GridItem(.adaptive(minimum: 125, maximum: 1024))]
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ScrollView {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
LazyVGrid(columns: columns, spacing: 6) {
|
|
|
|
ForEach(Icon.allCases) { icon in
|
|
|
|
Button {
|
|
|
|
currentIcon = icon.rawValue
|
|
|
|
if icon.rawValue == Icon.primary.rawValue {
|
|
|
|
UIApplication.shared.setAlternateIconName(nil)
|
|
|
|
} else {
|
|
|
|
UIApplication.shared.setAlternateIconName(icon.rawValue)
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
ZStack(alignment: .bottomTrailing) {
|
2022-12-27 21:35:41 +01:00
|
|
|
Image(uiImage: .init(named: icon.iconName) ?? .init())
|
2022-12-04 09:50:25 +01:00
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
.frame(minHeight: 125, maxHeight: 1024)
|
|
|
|
.cornerRadius(6)
|
|
|
|
.shadow(radius: 3)
|
|
|
|
if icon.rawValue == currentIcon {
|
|
|
|
Image(systemName: "checkmark.seal.fill")
|
|
|
|
.padding(4)
|
|
|
|
.tint(.green)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(6)
|
|
|
|
.navigationTitle("Icons")
|
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.background(theme.primaryBackgroundColor)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
}
|