summaryrefslogtreecommitdiff
path: root/Sora/Views
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-03-02 17:18:14 -0800
committerFuwn <[email protected]>2025-03-02 17:18:14 -0800
commit40fb6c23224c2d9aad265e8f671817028725dcf6 (patch)
treeddf0f1a6c96b666554c7bbe0fe20e94f820b0a84 /Sora/Views
parentfeat: Development commit (diff)
downloadsora-testing-40fb6c23224c2d9aad265e8f671817028725dcf6.tar.xz
sora-testing-40fb6c23224c2d9aad265e8f671817028725dcf6.zip
feat: Development commit
Diffstat (limited to 'Sora/Views')
-rw-r--r--Sora/Views/Post/Details/Carousel/PostDetailsCarouselItemView.swift37
-rw-r--r--Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift (renamed from Sora/Views/Post/Details/PostDetailsCarouselView.swift)25
-rw-r--r--Sora/Views/Post/Details/PostDetailsImageView.swift10
3 files changed, 46 insertions, 26 deletions
diff --git a/Sora/Views/Post/Details/Carousel/PostDetailsCarouselItemView.swift b/Sora/Views/Post/Details/Carousel/PostDetailsCarouselItemView.swift
new file mode 100644
index 0000000..c4aa292
--- /dev/null
+++ b/Sora/Views/Post/Details/Carousel/PostDetailsCarouselItemView.swift
@@ -0,0 +1,37 @@
+import SwiftUI
+
+struct PostDetailsCarouselItemView: View {
+ var post: BooruPost
+ var index: Int
+ @Binding var loadingStage: BooruPostLoadingState
+ var imageURL: (BooruPost) -> URL?
+ private var systemBackgroundColor: Color {
+ #if os(iOS)
+ return Color(.systemBackground)
+ #elseif os(macOS)
+ return Color(.windowBackgroundColor)
+ #else
+ return Color.gray
+ #endif
+ }
+
+ var body: some View {
+ ZStack {
+ PostDetailsImageView(
+ url: post.previewURL,
+ loadingStage: $loadingStage
+ )
+
+ PostDetailsImageView(
+ url: imageURL(post),
+ loadingStage: $loadingStage,
+ finalLoadingState: .loaded,
+ post: post
+ )
+ .background(
+ loadingStage == .loaded ? systemBackgroundColor : Color.clear
+ )
+ }
+ .tag(index)
+ }
+}
diff --git a/Sora/Views/Post/Details/PostDetailsCarouselView.swift b/Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift
index 6b4ba02..61d3aef 100644
--- a/Sora/Views/Post/Details/PostDetailsCarouselView.swift
+++ b/Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift
@@ -42,24 +42,13 @@ struct PostDetailsCarouselView: View {
var body: some View {
TabView(selection: $currentIndex) {
- ForEach(posts.indices, id: \.self) { index in
- ZStack {
- PostDetailsImageView(
- url: posts[index].previewURL,
- loadingStage: $loadingStage
- )
-
- PostDetailsImageView(
- url: imageURL(post: posts[index]),
- loadingStage: $loadingStage,
- finalLoadingState: .loaded,
- post: posts[index]
- )
- .background(
- loadingStage == .loaded ? Color(.systemBackground) : Color.clear
- )
- }
- .tag(index)
+ ForEach(Array(posts.enumerated()), id: \.offset) { index, post in
+ PostDetailsCarouselItemView(
+ post: post,
+ index: index,
+ loadingStage: $loadingStage,
+ imageURL: imageURL
+ )
}
}
.onChange(of: currentIndex) {
diff --git a/Sora/Views/Post/Details/PostDetailsImageView.swift b/Sora/Views/Post/Details/PostDetailsImageView.swift
index 92e95ed..483d435 100644
--- a/Sora/Views/Post/Details/PostDetailsImageView.swift
+++ b/Sora/Views/Post/Details/PostDetailsImageView.swift
@@ -89,17 +89,11 @@ struct PostDetailsImageView<Placeholder: View>: View {
}
)
.onAppear {
- if loadingState != .loaded {
- loadingState = finalLoadingState
- }
+ if loadingState != .loaded { loadingState = finalLoadingState }
}
} placeholder: {
placeholder()
- .onAppear {
- if loadingState != .loaded {
- loadingState = .loadingPreview
- }
- }
+ .onAppear { loadingState = .loadingPreview }
}
#if os(macOS)