blob: 53167319c8f7a8a27bf9b7fad633c549c49a7704 (
plain) (
blame)
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
|
import NetworkImage
import SwiftUI
struct PostGridThumbnailView: View {
@EnvironmentObject var settings: SettingsManager
@EnvironmentObject var manager: BooruManager
let post: BooruPost
let posts: [BooruPost]
let isNestedView: Bool
let endOfData: Bool
let onLoadNextPage: () async -> Void
let selectedPost: BooruPost?
private var thumbnailURL: URL? {
switch settings.thumbnailQuality {
case .preview:
post.previewURL
case .sample:
post.sampleURL
case .original:
post.fileURL
}
}
@ViewBuilder
private func primaryImageContent(image: Image) -> some View {
let isFiltered =
settings.blurRatings.contains(post.rating)
&& selectedPost?.id != post.id
image
.resizable()
.aspectRatio(contentMode: .fit)
.blur(radius: isFiltered ? 8 : 0)
.clipped()
.animation(.default, value: isFiltered)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
@ViewBuilder
private func imageContent(image: Image) -> some View {
if settings.uniformThumbnailGrid {
GeometryReader { proxy in
primaryImageContent(image: image)
.frame(width: proxy.size.width, height: proxy.size.width)
}
.clipped()
.aspectRatio(1, contentMode: .fit)
} else {
primaryImageContent(image: image)
}
}
var body: some View {
VStack {
NetworkImage(
url: thumbnailURL,
transaction: Transaction(animation: .default)
) { image in
if #available(iOS 18.0, macOS 15.0, *) {
imageContent(image: image)
.onScrollVisibilityChange { visible in
if posts.count > 4, post == posts[posts.count - (posts.count / 4)],
!endOfData, visible
{
Task(priority: .utility) { await onLoadNextPage() }
}
}
} else {
imageContent(image: image)
}
} placeholder: {
PostGridThumbnailPlaceholderView()
}
}
}
}
|