From 96d42756d5a9d5e535ee1a77e1fb167c07ff773e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 19 May 2024 15:00:25 -0400 Subject: [PATCH] Fix caption not displaying in gallery while image loading Closes #476 --- Tusker/Screens/Gallery/ImageGalleryDataSource.swift | 2 +- .../Gallery/LoadingGalleryContentViewController.swift | 6 ++++-- .../Gallery/StatusAttachmentsGalleryDataSource.swift | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Gallery/ImageGalleryDataSource.swift b/Tusker/Screens/Gallery/ImageGalleryDataSource.swift index 22b6d4dc..832fa5bf 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 e8ef4e9d..89920637 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 c2c53b0d..1119b12a 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)