Mercurial > public > lazybear
view LazyBear/UI/IconPicker.swift @ 287:22eba376075e
Add custom haptics
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sat, 20 Mar 2021 15:01:05 +0100 |
parents | 62f2c675b666 |
children |
line wrap: on
line source
// // IconPicker.swift // LazyBear // // Created by Dennis Concepción Martín on 26/2/21. // import SwiftUI struct IconPicker: View { var body: some View { List { Section(header: Text("White background")) { ForEach(icons, id: \.name) { icon in if !icon.background { IconRow(icon: icon) } } } Section(header: Text("Black background")) { ForEach(icons, id: \.name) { icon in if icon.background { IconRow(icon: icon) } } } } .listStyle(GroupedListStyle()) } } struct IconRow: View { @Environment(\.colorScheme) var colorScheme // Detect dark mode @EnvironmentObject var hapticsManager: HapticsManager var icon: IconModel var body: some View { Button(action: { hapticsManager.complexSuccess(); changeIcon(key: icon.file) }) { HStack { Image(icon.file) .resizable() .cornerRadius(20) .frame(width: 70, height: 70) Text(icon.name) .foregroundColor(colorScheme == .dark ? .white: .black) } } } private func changeIcon(key: String) { if key != "defaultIcon" { UIApplication.shared.setAlternateIconName(key) { error in if let error = error { print(error.localizedDescription) } else { print("Success!") } } } else { UIApplication.shared.setAlternateIconName(nil) } } } struct IconPicker_Previews: PreviewProvider { static var previews: some View { NavigationView { IconPicker() } } }