Better image loading placeholder

This commit is contained in:
Thomas Ricouard 2022-12-22 19:00:23 +01:00
parent fc77dd14fe
commit 0679559ced
4 changed files with 20 additions and 32 deletions

View file

@ -1,4 +1,5 @@
import SwiftUI import SwiftUI
import Shimmer
public struct AvatarView: View { public struct AvatarView: View {
public enum Size { public enum Size {
@ -35,10 +36,13 @@ public struct AvatarView: View {
if size == .badge { if size == .badge {
Circle() Circle()
.fill(.gray) .fill(.gray)
.frame(maxWidth: size.size.width, maxHeight: size.size.height) .frame(width: size.size.width, height: size.size.height)
.shimmering()
} else { } else {
ProgressView() RoundedRectangle(cornerRadius: size == .profile ? 4 : size.size.width / 2)
.frame(maxWidth: size.size.width, maxHeight: size.size.height) .fill(.gray)
.frame(width: size.size.width, height: size.size.height)
.shimmering()
} }
case let .success(image): case let .success(image):
image.resizable() image.resizable()

View file

@ -17,16 +17,12 @@ struct NotificationRowView: View {
.onTapGesture { .onTapGesture {
routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account)) routeurPath.navigate(to: .accountDetailWithAccount(account: notification.account))
} }
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 0) { HStack(spacing: 0) {
Image(systemName: type.iconName())
.resizable()
.frame(width: 16, height: 16)
.aspectRatio(contentMode: .fit)
.padding(.horizontal, 4)
if type.displayAccountName() { if type.displayAccountName() {
notification.account.displayNameWithEmojis notification.account.displayNameWithEmojis
.font(.subheadline) .font(.subheadline)
.fontWeight(.semibold)
Text(" ") Text(" ")
} }
Text(type.label()) Text(type.label())
@ -85,25 +81,6 @@ extension Models.Notification.NotificationType {
return "has been edited" 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 { struct NotificationRowView_Previews: PreviewProvider {

View file

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
import Models import Models
import Shimmer
struct StatusCardView: View { struct StatusCardView: View {
@Environment(\.openURL) private var openURL @Environment(\.openURL) private var openURL
@ -18,8 +19,10 @@ struct StatusCardView: View {
.clipped() .clipped()
}, },
placeholder: { placeholder: {
ProgressView() Rectangle()
.frame(maxWidth: 40, maxHeight: 40) .fill(Color.gray)
.frame(height: 200)
.shimmering()
} }
) )
} }

View file

@ -2,6 +2,7 @@ import SwiftUI
import Models import Models
import AVKit import AVKit
import Env import Env
import Shimmer
private class VideoPlayerViewModel: ObservableObject { private class VideoPlayerViewModel: ObservableObject {
@Published var player: AVPlayer? @Published var player: AVPlayer?
@ -87,8 +88,11 @@ public struct StatusMediaPreviewView: View {
.frame(width: proxy.frame(in: .local).width) .frame(width: proxy.frame(in: .local).width)
}, },
placeholder: { placeholder: {
ProgressView() RoundedRectangle(cornerRadius: 4)
.frame(maxWidth: 80, maxHeight: 80) .fill(Color.gray)
.frame(height: attachements.count > 2 ? 100 : 200)
.frame(width: proxy.frame(in: .local).width)
.shimmering()
} }
) )
case .gifv: case .gifv: