-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added file manually because git has gone completely awol
- Loading branch information
1 parent
25fd82c
commit 08b5e5e
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
Mlem/Views/Tabs/Settings/Components/Views/Appearance/Icon/AlternativeIconLabel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// AlternativeIconCell.swift | ||
// Mlem | ||
// | ||
// Created by tht7 on 28/06/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AlternativeIconLabel: View { | ||
let icon: AlternativeIcon | ||
|
||
var body: some View { | ||
HStack { | ||
getImage() | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: AppConstants.appIconSize, height: AppConstants.appIconSize) | ||
.foregroundColor(Color.white) | ||
.cornerRadius(AppConstants.appIconCornerRadius) | ||
.overlay { | ||
RoundedRectangle(cornerRadius: AppConstants.appIconCornerRadius) | ||
.stroke(Color(.secondarySystemBackground), lineWidth: 1) | ||
} | ||
VStack(alignment: .leading) { | ||
Text(icon.name) | ||
if let author = icon.author { | ||
Text(author) | ||
.font(.footnote) | ||
.foregroundColor(.secondary) | ||
} | ||
} | ||
Spacer() | ||
if icon.selected { | ||
Image(systemName: Icons.success) | ||
} | ||
} | ||
} | ||
|
||
func getImage() -> Image { | ||
let image = { | ||
guard let id = icon.id else { | ||
return Bundle.main.iconFileName | ||
.flatMap { UIImage(named: $0) } | ||
.map { | ||
Image(uiImage: $0) | ||
} ?? Image(systemName: Icons.noFile) | ||
} | ||
return Image(uiImage: UIImage(named: id) ?? UIImage(imageLiteralResourceName: id)) | ||
} | ||
|
||
return image() | ||
} | ||
} |