1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import SwiftUI
struct PostLoadingList: View {
let label: String
let placeholderIdentifier: String
let refreshIdentifier: String
var isActive = true
let refresh: () async -> Void
var body: some View {
GeometryReader { geometry in
List {
PostLoadingPlaceholder(label: label, count: max(1, Int(ceil(geometry.size.height / 108))))
.accessibilityIdentifier(placeholderIdentifier)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
}
.listStyle(.plain)
.refreshable { await refresh() }
.background {
ScrollRefreshControl(
isRefreshing: true, isActive: isActive,
accessibilityIdentifier: refreshIdentifier, accessibilityLabel: label
)
.allowsHitTesting(false)
.accessibilityHidden(true)
}
}
}
}
struct PostLoadingPlaceholder: View {
@AppStorage("hideAvatars") private var hideAvatars = false
@AppStorage("handlesOnly") private var handlesOnly = false
private var displayPreferences: DisplayPreferences {
DisplayPreferences(hideAvatars: hideAvatars, handlesOnly: handlesOnly)
}
let label: String
var count: Int?
var body: some View {
Group {
if let count {
rows(count: count)
} else {
GeometryReader { geometry in
rows(count: max(1, Int(ceil(geometry.size.height / 108))))
.frame(maxHeight: .infinity, alignment: .top)
.clipped()
}
}
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(label)
}
private func rows(count: Int) -> some View {
VStack(alignment: .leading, spacing: 24) {
ForEach(0..<count, id: \.self) { _ in
VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 10) {
if !displayPreferences.hideAvatars {
Circle().frame(width: 44, height: 44)
}
VStack(alignment: .leading, spacing: 6) {
Capsule().frame(width: 120, height: 10)
if !displayPreferences.handlesOnly {
Capsule().frame(width: 90, height: 8)
}
}
}
Capsule().frame(height: 10)
Capsule().frame(maxWidth: .infinity, alignment: .leading).frame(height: 10).padding(.trailing, 70)
}
}
}
.foregroundStyle(.quaternary)
.padding(16)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
}