mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
Only show media captions in QuickLook once. (#6287)
This commit is contained in:
+23
-2
@@ -22,6 +22,9 @@ class TimelineMediaPreviewController: QLPreviewController {
|
|||||||
|
|
||||||
private var barButtonTimer: Timer?
|
private var barButtonTimer: Timer?
|
||||||
|
|
||||||
|
/// When not nil, the given item will have its caption hidden.
|
||||||
|
private var captionHiddenForItemID: MediaPreviewItemID?
|
||||||
|
|
||||||
@CancellableTask private var settledRefreshTask: Task<Void, Never>?
|
@CancellableTask private var settledRefreshTask: Task<Void, Never>?
|
||||||
/// Media whose file loaded, kept until the swipe settles as each load is only reported once.
|
/// Media whose file loaded, kept until the swipe settles as each load is only reported once.
|
||||||
/// Whichever is on display by then gets refreshed and the rest are dropped.
|
/// Whichever is on display by then gets refreshed and the rest are dropped.
|
||||||
@@ -59,6 +62,10 @@ class TimelineMediaPreviewController: QLPreviewController {
|
|||||||
captionHostingController.view
|
captionHostingController.view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var currentPreviewItemMediaID: MediaPreviewItemID? {
|
||||||
|
(currentPreviewItem as? TimelineMediaPreviewItem.Media)?.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether the displayed placeholder's index now holds a media, or a different placeholder
|
/// Whether the displayed placeholder's index now holds a media, or a different placeholder
|
||||||
/// having reached the end of the timeline, in which case what's on display is stale.
|
/// having reached the end of the timeline, in which case what's on display is stale.
|
||||||
private var isDisplayedPlaceholderStale: Bool {
|
private var isDisplayedPlaceholderStale: Bool {
|
||||||
@@ -204,8 +211,14 @@ class TimelineMediaPreviewController: QLPreviewController {
|
|||||||
private func updateCaptionVisibility() {
|
private func updateCaptionVisibility() {
|
||||||
// The caption should be hidden alongside the header.
|
// The caption should be hidden alongside the header.
|
||||||
let isHeaderHidden = headerHostingController.view.window == nil
|
let isHeaderHidden = headerHostingController.view.window == nil
|
||||||
if captionView.isHidden != isHeaderHidden {
|
let currentItemID = currentPreviewItemMediaID
|
||||||
captionView.isHidden = isHeaderHidden
|
|
||||||
|
let isHidden = isHeaderHidden || currentItemID == captionHiddenForItemID
|
||||||
|
if captionView.isHidden != isHidden {
|
||||||
|
captionView.isHidden = isHidden
|
||||||
|
if isHidden {
|
||||||
|
captionHiddenForItemID = currentItemID // Don't show the caption again for this item.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,6 +264,14 @@ class TimelineMediaPreviewController: QLPreviewController {
|
|||||||
private func loadCurrentItem() {
|
private func loadCurrentItem() {
|
||||||
headerHostingController.view.sizeToFit() // Resizing isn't automatic in the toolbar 😒
|
headerHostingController.view.sizeToFit() // Resizing isn't automatic in the toolbar 😒
|
||||||
|
|
||||||
|
if #available(iOS 26, *), view.window != nil {
|
||||||
|
if captionHiddenForItemID != currentPreviewItemMediaID {
|
||||||
|
captionHiddenForItemID = nil // Allow the caption to be re-shown when swiping.
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCaptionVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
if let previewItem = currentPreviewItem as? TimelineMediaPreviewItem.Media {
|
if let previewItem = currentPreviewItem as? TimelineMediaPreviewItem.Media {
|
||||||
context.send(viewAction: .updateCurrentItem(.media(previewItem)))
|
context.send(viewAction: .updateCurrentItem(.media(previewItem)))
|
||||||
} else if let loadingItem = currentPreviewItem as? TimelineMediaPreviewItem.Loading {
|
} else if let loadingItem = currentPreviewItem as? TimelineMediaPreviewItem.Loading {
|
||||||
|
|||||||
Reference in New Issue
Block a user