Fix caption not displaying in gallery while image loading

Closes #476
This commit is contained in:
Shadowfacts 2024-05-19 15:00:25 -04:00
parent f6e57d664f
commit 96d42756d5
3 changed files with 8 additions and 5 deletions

View File

@ -42,7 +42,7 @@ class ImageGalleryDataSource: GalleryDataSource {
gifController: gifController gifController: gifController
) )
} else { } else {
return LoadingGalleryContentViewController { return LoadingGalleryContentViewController(caption: nil) {
let (data, image) = await self.cache.get(self.url, loadOriginal: true) let (data, image) = await self.cache.get(self.url, loadOriginal: true)
if let image { if let image {
let gifController: GIFController? = let gifController: GIFController? =

View File

@ -10,6 +10,7 @@ import UIKit
import GalleryVC import GalleryVC
class LoadingGalleryContentViewController: UIViewController, GalleryContentViewController { class LoadingGalleryContentViewController: UIViewController, GalleryContentViewController {
private let fallbackCaption: String?
private let provider: () async -> (any GalleryContentViewController)? private let provider: () async -> (any GalleryContentViewController)?
private var wrapped: (any GalleryContentViewController)! private var wrapped: (any GalleryContentViewController)!
@ -24,14 +25,15 @@ class LoadingGalleryContentViewController: UIViewController, GalleryContentViewC
} }
var caption: String? { var caption: String? {
wrapped?.caption wrapped?.caption ?? fallbackCaption
} }
var canAnimateFromSourceView: Bool { var canAnimateFromSourceView: Bool {
wrapped?.canAnimateFromSourceView ?? true wrapped?.canAnimateFromSourceView ?? true
} }
init(provider: @escaping () async -> (any GalleryContentViewController)?) { init(caption: String?, provider: @escaping () async -> (any GalleryContentViewController)?) {
self.fallbackCaption = caption
self.provider = provider self.provider = provider
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)

View File

@ -57,7 +57,8 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource {
gifController: gifController gifController: gifController
) )
} else { } 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) let (data, image) = await ImageCache.attachments.get(attachment.url, loadOriginal: true)
if let image { if let image {
let gifController: GIFController? = let gifController: GIFController? =
@ -95,7 +96,7 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource {
// TODO: use separate content VC with audio visualization? // TODO: use separate content VC with audio visualization?
return VideoGalleryContentViewController(url: attachment.url, caption: attachment.description) return VideoGalleryContentViewController(url: attachment.url, caption: attachment.description)
case .unknown: case .unknown:
return LoadingGalleryContentViewController { return LoadingGalleryContentViewController(caption: nil) {
do { do {
let (data, _) = try await URLSession.shared.data(from: attachment.url) let (data, _) = try await URLSession.shared.data(from: attachment.url)
let url = FileManager.default.temporaryDirectory.appendingPathComponent(attachment.url.lastPathComponent) let url = FileManager.default.temporaryDirectory.appendingPathComponent(attachment.url.lastPathComponent)