summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-03-01 00:35:26 -0800
committerFuwn <[email protected]>2025-03-01 00:35:32 -0800
commit83113da4692cc60e394f9c7af89882e7ec5ca877 (patch)
tree8382220281eaedf9f6f2c817ee1f8e77f523f383
parentfeat: Development commit (diff)
downloadsora-testing-83113da4692cc60e394f9c7af89882e7ec5ca877.tar.xz
sora-testing-83113da4692cc60e394f9c7af89882e7ec5ca877.zip
feat: Development commit
-rw-r--r--Sora/Views/InteractiveImageView.swift2
-rw-r--r--Sora/Views/Post/Details/PostDetailsCarouselView.swift69
-rw-r--r--Sora/Views/Post/Details/PostDetailsView.swift41
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift3
4 files changed, 97 insertions, 18 deletions
diff --git a/Sora/Views/InteractiveImageView.swift b/Sora/Views/InteractiveImageView.swift
index e7ddea2..052e9cd 100644
--- a/Sora/Views/InteractiveImageView.swift
+++ b/Sora/Views/InteractiveImageView.swift
@@ -46,7 +46,7 @@ struct InteractiveImageView<MenuItems: View>: View {
previousScale = currentScale
}
.simultaneously(
- with: DragGesture(minimumDistance: 0)
+ with: (currentScale > 1 ? DragGesture(minimumDistance: 0) : nil)
.onChanged { gesture in
withAnimation(.interactiveSpring()) {
var newOffset: CGSize = .zero
diff --git a/Sora/Views/Post/Details/PostDetailsCarouselView.swift b/Sora/Views/Post/Details/PostDetailsCarouselView.swift
new file mode 100644
index 0000000..378b9cc
--- /dev/null
+++ b/Sora/Views/Post/Details/PostDetailsCarouselView.swift
@@ -0,0 +1,69 @@
+import SwiftUI
+
+struct PostDetailsCarouselView: View {
+ @EnvironmentObject var manager: BooruManager
+ @EnvironmentObject var settings: SettingsManager
+ let posts: [BooruPost]
+ let focusedPost: BooruPost?
+ @Binding var loadingStage: BooruPostLoadingState
+ @State private var currentIndex: Int
+
+ init(
+ posts: [BooruPost],
+ loadingStage: Binding<BooruPostLoadingState>,
+ focusedPost: BooruPost? = nil
+ ) {
+ self.posts = posts
+ self.focusedPost = focusedPost
+ _loadingStage = loadingStage
+
+ if let focused = focusedPost,
+ let index = posts.firstIndex(where: { $0.id == focused.id })
+ {
+ self._currentIndex = State(initialValue: index)
+ } else {
+ self._currentIndex = State(initialValue: 0)
+ }
+ }
+
+ func imageURL(post: BooruPost) -> URL? {
+ switch settings.detailViewQuality {
+ case .preview:
+ post.previewURL
+
+ case .sample:
+ post.sampleURL
+
+ case .original:
+ post.fileURL
+ }
+ }
+
+ var body: some View {
+ TabView(selection: $currentIndex) {
+ ForEach(posts.indices, id: \.self) { index in
+ ZStack {
+ PostDetailsImageView(
+ url: posts[index].previewURL,
+ loadingStage: $loadingStage
+ )
+ .opacity(loadingStage == .loaded ? 0 : 1)
+
+ PostDetailsImageView(
+ url: imageURL(post: posts[index]),
+ loadingStage: $loadingStage,
+ finalLoadingState: .loaded,
+ post: posts[index]
+ )
+ }
+ .tag(index)
+ }
+ }
+ .onChange(of: currentIndex) {
+ if currentIndex == posts.count - 1 { manager.loadNextPage() }
+ }
+ #if !os(macOS)
+ .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
+ #endif
+ }
+}
diff --git a/Sora/Views/Post/Details/PostDetailsView.swift b/Sora/Views/Post/Details/PostDetailsView.swift
index 596cbbd..4662f4a 100644
--- a/Sora/Views/Post/Details/PostDetailsView.swift
+++ b/Sora/Views/Post/Details/PostDetailsView.swift
@@ -19,27 +19,36 @@ struct PostDetailsView: View {
}
@State private var isTagsSheetPresented = false
+ var filteredPosts: [BooruPost] {
+ manager.posts
+ .filter { settings.displayRatings.contains($0.rating) }
+ .sorted { $0.id > $1.id }
+ }
+
var body: some View {
VStack(spacing: 0) {
- PostDetailsImageView(
- url: imageURL,
- loadingStage: $loadingStage,
- finalLoadingState: .loaded,
- post: post
- ) {
+ #if os(macOS)
PostDetailsImageView(
- url: post.previewURL,
- loadingStage: $loadingStage
+ url: imageURL,
+ loadingStage: $loadingStage,
+ finalLoadingState: .loaded,
+ post: post
+ ) {
+ PostDetailsImageView(
+ url: post.previewURL,
+ loadingStage: $loadingStage
+ )
+ .id(post.previewURL)
+ }
+ .id(imageURL)
+ #else
+ PostDetailsCarouselView(
+ posts: filteredPosts,
+ loadingStage: $loadingStage,
+ focusedPost: post
)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
- .id(post.previewURL)
- .padding(0)
- .zIndex(0)
- }
- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
- .id(imageURL)
- .padding(0)
- .zIndex(0)
+ #endif
if settings.displayDetailsInformationBar {
VStack(spacing: 5) {
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index a3b5f31..20d6b3a 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -11,7 +11,8 @@ struct PostGridView: View {
private var isSearching
var filteredPosts: [BooruPost] {
- manager.posts.filter { settings.displayRatings.contains($0.rating) }
+ manager.posts
+ .filter { settings.displayRatings.contains($0.rating) }
.sorted { $0.id > $1.id }
}