diff options
Diffstat (limited to 'Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift')
| -rw-r--r-- | Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift b/Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift index 88714c3..3ead408 100644 --- a/Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift +++ b/Sora/Views/Post/Details/Carousel/PostDetailsCarouselView.swift @@ -1,24 +1,24 @@ import SwiftUI struct PostDetailsCarouselView: View { - @ObservedObject var manager: BooruManager @EnvironmentObject var settings: SettingsManager let posts: [BooruPost] let focusedPost: BooruPost? @Binding var loadingStage: BooruPostLoadingState @State private var currentIndex: Int private let cacheManager = ImageCacheManager.shared + @Binding var selectedPost: (post: BooruPost?, manager: BooruManager?) init( posts: [BooruPost], loadingStage: Binding<BooruPostLoadingState>, focusedPost: BooruPost? = nil, - manager: ObservedObject<BooruManager> + selectedPost: Binding<(post: BooruPost?, manager: BooruManager?)> ) { self.posts = posts self.focusedPost = focusedPost _loadingStage = loadingStage - _manager = manager + _selectedPost = selectedPost if let focused = focusedPost, let index = posts.firstIndex(where: { $0.id == focused.id }) @@ -46,18 +46,19 @@ struct PostDetailsCarouselView: View { TabView(selection: $currentIndex) { ForEach(Array(posts.enumerated()), id: \.offset) { index, post in PostDetailsCarouselItemView( - post: post, - manager: manager, index: index, loadingStage: $loadingStage, - imageURL: imageURL + imageURL: imageURL, + selectedPost: $selectedPost ) } } .onChange(of: currentIndex) { + guard let manager = selectedPost.manager else { return } + if currentIndex == posts.count - 1 { manager.loadNextPage() } - manager.selectedPost = posts[currentIndex] + selectedPost.post = posts[currentIndex] preloadNearbyImages() } |