From d4dd16698dd6eda70b6949d9c8656ef8735b1844 Mon Sep 17 00:00:00 2001 From: Marcin Czachursk Date: Mon, 10 Apr 2023 21:53:15 +0200 Subject: [PATCH] Avatars improvements --- CoreData/ApplicationSettingsHandler.swift | 1 + Vernissage.xcodeproj/project.pbxproj | 4 ++++ Vernissage/ViewModifiers/ImageAvatar.swift | 5 ++-- VernissageWidget/Extensions/Avatar.swift | 24 +++++++++++++++++++ VernissageWidget/Views/LargeWidgetView.swift | 14 +++-------- VernissageWidget/Views/MediumWidgetView.swift | 14 +++-------- VernissageWidget/Views/SmallWidgetView.swift | 11 +-------- 7 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 VernissageWidget/Extensions/Avatar.swift diff --git a/CoreData/ApplicationSettingsHandler.swift b/CoreData/ApplicationSettingsHandler.swift index 0143946..6503d8f 100644 --- a/CoreData/ApplicationSettingsHandler.swift +++ b/CoreData/ApplicationSettingsHandler.swift @@ -54,6 +54,7 @@ class ApplicationSettingsHandler { applicationState.activeIcon = defaultSettings.activeIcon applicationState.showSensitive = defaultSettings.showSensitive applicationState.showPhotoDescription = defaultSettings.showPhotoDescription + applicationState.showAvatarsOnTimeline = defaultSettings.showAvatarsOnTimeline if let menuPosition = MenuPosition(rawValue: Int(defaultSettings.menuPosition)) { applicationState.menuPosition = menuPosition diff --git a/Vernissage.xcodeproj/project.pbxproj b/Vernissage.xcodeproj/project.pbxproj index f16e69c..9ff84fc 100644 --- a/Vernissage.xcodeproj/project.pbxproj +++ b/Vernissage.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ F805DCF129DBEF83006A1FD9 /* ReportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F805DCF029DBEF83006A1FD9 /* ReportView.swift */; }; F808641429756666009F035C /* NotificationRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F808641329756666009F035C /* NotificationRowView.swift */; }; F8121CA8298A86D600B466C7 /* InstanceRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8121CA7298A86D600B466C7 /* InstanceRowView.swift */; }; + F815F60C29E49CF20044566B /* Avatar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F815F60B29E49CF20044566B /* Avatar.swift */; }; F8210DCF2966B600001D9973 /* ImageRowAsync.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8210DCE2966B600001D9973 /* ImageRowAsync.swift */; }; F8210DD52966BB7E001D9973 /* Nuke in Frameworks */ = {isa = PBXBuildFile; productRef = F8210DD42966BB7E001D9973 /* Nuke */; }; F8210DD72966BB7E001D9973 /* NukeExtensions in Frameworks */ = {isa = PBXBuildFile; productRef = F8210DD62966BB7E001D9973 /* NukeExtensions */; }; @@ -220,6 +221,7 @@ F805DCF029DBEF83006A1FD9 /* ReportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportView.swift; sourceTree = ""; }; F808641329756666009F035C /* NotificationRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationRowView.swift; sourceTree = ""; }; F8121CA7298A86D600B466C7 /* InstanceRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceRowView.swift; sourceTree = ""; }; + F815F60B29E49CF20044566B /* Avatar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Avatar.swift; sourceTree = ""; }; F8210DCE2966B600001D9973 /* ImageRowAsync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageRowAsync.swift; sourceTree = ""; }; F8210DDC2966CF17001D9973 /* StatusData+Status.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatusData+Status.swift"; sourceTree = ""; }; F8210DDE2966CFC7001D9973 /* AttachmentData+Attachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AttachmentData+Attachment.swift"; sourceTree = ""; }; @@ -784,6 +786,7 @@ F8F6E44F29BCE9030004795E /* Extensions */ = { isa = PBXGroup; children = ( + F815F60B29E49CF20044566B /* Avatar.swift */, F8F6E45029BCE9190004795E /* UIImage+Resize.swift */, ); path = Extensions; @@ -983,6 +986,7 @@ F8F6E44C29BCC1F70004795E /* SmallWidgetView.swift in Sources */, F864F76629BB91B400B13921 /* VernissageWidget.swift in Sources */, F8F6E44D29BCC1F90004795E /* MediumWidgetView.swift in Sources */, + F815F60C29E49CF20044566B /* Avatar.swift in Sources */, F8F6E44E29BCC1FB0004795E /* LargeWidgetView.swift in Sources */, F864F76429BB91B400B13921 /* VernissageWidgetBundle.swift in Sources */, F864F77D29BB9A4600B13921 /* AttachmentData+CoreDataClass.swift in Sources */, diff --git a/Vernissage/ViewModifiers/ImageAvatar.swift b/Vernissage/ViewModifiers/ImageAvatar.swift index bfec065..86254de 100644 --- a/Vernissage/ViewModifiers/ImageAvatar.swift +++ b/Vernissage/ViewModifiers/ImageAvatar.swift @@ -19,7 +19,7 @@ public extension View { private struct ImageAvatar: ViewModifier { @EnvironmentObject var applicationState: ApplicationState - + private let displayName: String? private let avatarUrl: URL? @@ -49,7 +49,8 @@ private struct ImageAvatar: ViewModifier { } Text(displayName ?? "") - .foregroundColor(.white) + .font(.subheadline) + .foregroundColor(.white.opacity(0.8)) .fontWeight(.semibold) .shadow(color: .black, radius: 2) Spacer() diff --git a/VernissageWidget/Extensions/Avatar.swift b/VernissageWidget/Extensions/Avatar.swift new file mode 100644 index 0000000..2ba0265 --- /dev/null +++ b/VernissageWidget/Extensions/Avatar.swift @@ -0,0 +1,24 @@ +// +// https://mczachurski.dev +// Copyright © 2023 Marcin Czachurski and the repository contributors. +// Licensed under the Apache License 2.0. +// + +import Foundation +import SwiftUI + +extension Image { + func avatar(size: Double) -> some View { + self + .resizable() + .clipShape(Circle()) + .aspectRatio(contentMode: .fit) + .frame(width: size, height: size) + .overlay( + Circle() + .stroke(Color.white.opacity(0.6), lineWidth: 1) + .frame(width: size, height: size) + ) + .shadow(color: .black, radius: 2) + } +} diff --git a/VernissageWidget/Views/LargeWidgetView.swift b/VernissageWidget/Views/LargeWidgetView.swift index 058750d..0832d4e 100644 --- a/VernissageWidget/Views/LargeWidgetView.swift +++ b/VernissageWidget/Views/LargeWidgetView.swift @@ -26,19 +26,11 @@ struct LargeWidgetView: View { Spacer() HStack { uiAvatar - .resizable() - .clipShape(Circle()) - .aspectRatio(contentMode: .fit) - .frame(width: 24, height: 24) - .overlay( - Circle() - .stroke(Color.white.opacity(0.6), lineWidth: 1) - .frame(width: 24, height: 24) - ) - .shadow(color: .black, radius: 2) + .avatar(size: 24) Text(entry.displayName ?? "") - .foregroundColor(.white) + .font(.subheadline) + .foregroundColor(.white.opacity(0.8)) .fontWeight(.semibold) .shadow(color: .black, radius: 2) Spacer() diff --git a/VernissageWidget/Views/MediumWidgetView.swift b/VernissageWidget/Views/MediumWidgetView.swift index 276c24d..a63133f 100644 --- a/VernissageWidget/Views/MediumWidgetView.swift +++ b/VernissageWidget/Views/MediumWidgetView.swift @@ -26,19 +26,11 @@ struct MediumWidgetView: View { Spacer() HStack { uiAvatar - .resizable() - .clipShape(Circle()) - .aspectRatio(contentMode: .fit) - .frame(width: 24, height: 24) - .overlay( - Circle() - .stroke(Color.white.opacity(0.6), lineWidth: 1) - .frame(width: 24, height: 24) - ) - .shadow(color: .black, radius: 2) + .avatar(size: 24) Text(entry.displayName ?? "") - .foregroundColor(.white) + .font(.subheadline) + .foregroundColor(.white.opacity(0.8)) .fontWeight(.semibold) .shadow(color: .black, radius: 2) Spacer() diff --git a/VernissageWidget/Views/SmallWidgetView.swift b/VernissageWidget/Views/SmallWidgetView.swift index b686186..be1dd83 100644 --- a/VernissageWidget/Views/SmallWidgetView.swift +++ b/VernissageWidget/Views/SmallWidgetView.swift @@ -26,16 +26,7 @@ struct SmallWidgetView: View { Spacer() HStack { uiAvatar - .resizable() - .clipShape(Circle()) - .aspectRatio(contentMode: .fit) - .frame(width: 16, height: 16) - .overlay( - Circle() - .stroke(Color.white.opacity(0.6), lineWidth: 1) - .frame(width: 16, height: 16) - ) - .shadow(color: .black, radius: 2) + .avatar(size: 16) Spacer() }