diff options
Diffstat (limited to 'Sora/Views')
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsCarouselView.swift | 21 | ||||
| -rw-r--r-- | Sora/Views/Settings/Section/SettingsDetailsView.swift | 12 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Sora/Views/Post/Details/PostDetailsCarouselView.swift b/Sora/Views/Post/Details/PostDetailsCarouselView.swift index 378b9cc..de14477 100644 --- a/Sora/Views/Post/Details/PostDetailsCarouselView.swift +++ b/Sora/Views/Post/Details/PostDetailsCarouselView.swift @@ -7,6 +7,7 @@ struct PostDetailsCarouselView: View { let focusedPost: BooruPost? @Binding var loadingStage: BooruPostLoadingState @State private var currentIndex: Int + private let cacheManager = ImageCacheManager.shared init( posts: [BooruPost], @@ -61,9 +62,29 @@ struct PostDetailsCarouselView: View { } .onChange(of: currentIndex) { if currentIndex == posts.count - 1 { manager.loadNextPage() } + + preloadNearbyImages() } + .onAppear(perform: preloadNearbyImages) #if !os(macOS) .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never)) #endif } + + private func preloadNearbyImages() { + let preloadRange = settings.preloadedCarouselImages + let startIndex = max(0, currentIndex - preloadRange) + let endIndex = min(posts.count - 1, currentIndex + preloadRange) + var urlsToPreload: [URL] = [] + + for index in startIndex...endIndex { + if let url = imageURL(post: posts[index]) { + urlsToPreload.append(url) + } + + urlsToPreload.append(posts[index].previewURL) + } + + cacheManager.preloadImages(urlsToPreload) + } } diff --git a/Sora/Views/Settings/Section/SettingsDetailsView.swift b/Sora/Views/Settings/Section/SettingsDetailsView.swift index 5abd394..885ef6f 100644 --- a/Sora/Views/Settings/Section/SettingsDetailsView.swift +++ b/Sora/Views/Settings/Section/SettingsDetailsView.swift @@ -21,5 +21,17 @@ struct SettingsDetailsView: View { Text("Saves post tags in a file alongside the downloaded image.") } #endif + + #if os(macOS) + Picker("Preloaded Images", selection: $settings.preloadedCarouselImages) { + ForEach(1...10, id: \.self) { columns in Text("\(columns)") } + } + #else + Stepper( + "Preloaded Images: \(settings.preloadedCarouselImages)", + value: $settings.preloadedCarouselImages, + in: 1...10 + ) + #endif } } |