diff --git a/Tusker/Screens/Gallery/ImageGalleryDataSource.swift b/Tusker/Screens/Gallery/ImageGalleryDataSource.swift index 22b6d4dc6d..832fa5bf7d 100644 --- a/Tusker/Screens/Gallery/ImageGalleryDataSource.swift +++ b/Tusker/Screens/Gallery/ImageGalleryDataSource.swift @@ -42,7 +42,7 @@ class ImageGalleryDataSource: GalleryDataSource { gifController: gifController ) } else { - return LoadingGalleryContentViewController { + return LoadingGalleryContentViewController(caption: nil) { let (data, image) = await self.cache.get(self.url, loadOriginal: true) if let image { let gifController: GIFController? = diff --git a/Tusker/Screens/Gallery/LoadingGalleryContentViewController.swift b/Tusker/Screens/Gallery/LoadingGalleryContentViewController.swift index e8ef4e9d7e..899206373b 100644 --- a/Tusker/Screens/Gallery/LoadingGalleryContentViewController.swift +++ b/Tusker/Screens/Gallery/LoadingGalleryContentViewController.swift @@ -10,6 +10,7 @@ import UIKit import GalleryVC class LoadingGalleryContentViewController: UIViewController, GalleryContentViewController { + private let fallbackCaption: String? private let provider: () async -> (any GalleryContentViewController)? private var wrapped: (any GalleryContentViewController)! @@ -24,14 +25,15 @@ class LoadingGalleryContentViewController: UIViewController, GalleryContentViewC } var caption: String? { - wrapped?.caption + wrapped?.caption ?? fallbackCaption } var canAnimateFromSourceView: Bool { wrapped?.canAnimateFromSourceView ?? true } - init(provider: @escaping () async -> (any GalleryContentViewController)?) { + init(caption: String?, provider: @escaping () async -> (any GalleryContentViewController)?) { + self.fallbackCaption = caption self.provider = provider super.init(nibName: nil, bundle: nil) diff --git a/Tusker/Screens/Gallery/StatusAttachmentsGalleryDataSource.swift b/Tusker/Screens/Gallery/StatusAttachmentsGalleryDataSource.swift index c2c53b0dbf..1119b12ac1 100644 --- a/Tusker/Screens/Gallery/StatusAttachmentsGalleryDataSource.swift +++ b/Tusker/Screens/Gallery/StatusAttachmentsGalleryDataSource.swift @@ -57,7 +57,8 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource { gifController: gifController ) } else { - return LoadingGalleryContentViewController { + return LoadingGalleryContentViewController(caption: attachment.description) { + try! await Task.sleep(nanoseconds: NSEC_PER_SEC) let (data, image) = await ImageCache.attachments.get(attachment.url, loadOriginal: true) if let image { let gifController: GIFController? = @@ -95,7 +96,7 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource { // TODO: use separate content VC with audio visualization? return VideoGalleryContentViewController(url: attachment.url, caption: attachment.description) case .unknown: - return LoadingGalleryContentViewController { + return LoadingGalleryContentViewController(caption: nil) { do { let (data, _) = try await URLSession.shared.data(from: attachment.url) let url = FileManager.default.temporaryDirectory.appendingPathComponent(attachment.url.lastPathComponent)