From 0679559ceda4b59682d22d08167aa6316df04196 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 22 Dec 2022 19:00:23 +0100 Subject: [PATCH] Better image loading placeholder --- .../DesignSystem/Views/AvatarView.swift | 10 ++++--- .../Notifications/NotificationRowView.swift | 27 ++----------------- .../Sources/Status/Row/StatusCardView.swift | 7 +++-- .../Status/Row/StatusMediaPreviewView.swift | 8 ++++-- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift index 6c5ab986..1b73381d 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift @@ -1,4 +1,5 @@ import SwiftUI +import Shimmer public struct AvatarView: View { public enum Size { @@ -35,10 +36,13 @@ public struct AvatarView: View { if size == .badge { Circle() .fill(.gray) - .frame(maxWidth: size.size.width, maxHeight: size.size.height) + .frame(width: size.size.width, height: size.size.height) + .shimmering() } else { - ProgressView() - .frame(maxWidth: size.size.width, maxHeight: size.size.height) + RoundedRectangle(cornerRadius: size == .profile ? 4 : size.size.width / 2) + .fill(.gray) + .frame(width: size.size.width, height: size.size.height) + .shimmering() } case let .success(image): image.resizable() diff --git a/Packages/Notifications/Sources/Notifications/NotificationRowView.swift b/Packages/Notifications/Sources/Notifications/NotificationRowView.swift index bf6b6ed9..b74e655f 100644 --- a/Packages/Notifications/Sources/Notifications/NotificationRowView.swift +++ b/Packages/Notifications/Sources/Notifications/NotificationRowView.swift @@ -17,16 +17,12 @@ struct NotificationRowView: View { .onTapGesture { routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account)) } - VStack(alignment: .leading, spacing: 4) { + VStack(alignment: .leading, spacing: 0) { HStack(spacing: 0) { - Image(systemName: type.iconName()) - .resizable() - .frame(width: 16, height: 16) - .aspectRatio(contentMode: .fit) - .padding(.horizontal, 4) if type.displayAccountName() { notification.account.displayNameWithEmojis .font(.subheadline) + .fontWeight(.semibold) Text(" ") } Text(type.label()) @@ -85,25 +81,6 @@ extension Models.Notification.NotificationType { return "has been edited" } } - - func iconName() -> String { - switch self { - case .status: - return "pencil" - case .mention: - return "at.circle.fill" - case .reblog: - return "arrow.left.arrow.right.circle.fill" - case .follow, .follow_request: - return "person.fill.badge.plus" - case .favourite: - return "star.fill" - case .poll: - return "chart.bar.fill" - case .update: - return "pencil.line" - } - } } struct NotificationRowView_Previews: PreviewProvider { diff --git a/Packages/Status/Sources/Status/Row/StatusCardView.swift b/Packages/Status/Sources/Status/Row/StatusCardView.swift index cdd71587..d84553b3 100644 --- a/Packages/Status/Sources/Status/Row/StatusCardView.swift +++ b/Packages/Status/Sources/Status/Row/StatusCardView.swift @@ -1,5 +1,6 @@ import SwiftUI import Models +import Shimmer struct StatusCardView: View { @Environment(\.openURL) private var openURL @@ -18,8 +19,10 @@ struct StatusCardView: View { .clipped() }, placeholder: { - ProgressView() - .frame(maxWidth: 40, maxHeight: 40) + Rectangle() + .fill(Color.gray) + .frame(height: 200) + .shimmering() } ) } diff --git a/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift b/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift index 097cba6d..1e7e40e9 100644 --- a/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift +++ b/Packages/Status/Sources/Status/Row/StatusMediaPreviewView.swift @@ -2,6 +2,7 @@ import SwiftUI import Models import AVKit import Env +import Shimmer private class VideoPlayerViewModel: ObservableObject { @Published var player: AVPlayer? @@ -87,8 +88,11 @@ public struct StatusMediaPreviewView: View { .frame(width: proxy.frame(in: .local).width) }, placeholder: { - ProgressView() - .frame(maxWidth: 80, maxHeight: 80) + RoundedRectangle(cornerRadius: 4) + .fill(Color.gray) + .frame(height: attachements.count > 2 ? 100 : 200) + .frame(width: proxy.frame(in: .local).width) + .shimmering() } ) case .gifv: