Skip to content

Commit 617e88f

Browse files
committed
Added colors to filetype icons
1 parent 348a7df commit 617e88f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

MacImageManager/MacImageManager/Views/FileBrowserRowView.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SwiftUI
9+
import UniformTypeIdentifiers
910

1011
struct FileBrowserRowView: View {
1112
@EnvironmentObject var browserModel: BrowserModel
@@ -15,7 +16,8 @@ struct FileBrowserRowView: View {
1516
HStack {
1617
Image(systemName: item.iconName)
1718
.font(.system(size: 24))
18-
.foregroundColor(item.isDirectory ? .blue : .orange)
19+
.symbolRenderingMode(.hierarchical)
20+
.foregroundStyle(tint(for: item))
1921
.frame(width: 32, height: 32)
2022

2123
VStack(alignment: .leading) {
@@ -58,6 +60,27 @@ struct FileBrowserRowView: View {
5860
}
5961
}
6062
}
63+
64+
private func tint(for item: FileItem) -> Color {
65+
if item.isDirectory { return .blue }
66+
guard let type = item.uti else { return .secondary }
67+
68+
if type == .livePhoto { return .yellow }
69+
if type.conforms(to: .gif) { return .pink }
70+
if type == .svg { return .green }
71+
if type.conforms(to: .rawImage) { return .indigo }
72+
if type == .heic || type == .heif { return .orange }
73+
if type.conforms(to: .image) { return .teal }
74+
if type.conforms(to: .movie) { return .red }
75+
if type == .pdf { return .brown }
76+
if type.conforms(to: .archive) { return .brown }
77+
if type.conforms(to: .audio) { return .mint }
78+
if type.conforms(to: .json) { return .cyan }
79+
if type.conforms(to: .sourceCode) { return .gray }
80+
if type.conforms(to: .plainText) { return .gray }
81+
82+
return .secondary
83+
}
6184
}
6285

6386
#Preview {

0 commit comments

Comments
 (0)