Skip to content

Commit

Permalink
Fix a bug where the preview controller breaks when swiping quickly.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Feb 6, 2025
1 parent 7560f2c commit d7e39f1
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TimelineMediaPreviewController: QLPreviewController {

private var navigationBar: UINavigationBar? { view.subviews.first?.subviews.first { $0 is UINavigationBar } as? UINavigationBar }
private var toolbar: UIToolbar? { view.subviews.first?.subviews.last { $0 is UIToolbar } as? UIToolbar }
private var pageScrollView: UIScrollView? { view.subviews.first?.subviews.first?.subviews.first?.subviews.first?.subviews.first?.subviews.first as? UIScrollView }
private var captionView: UIView { captionHostingController.view }

override var overrideUserInterfaceStyle: UIUserInterfaceStyle {
Expand Down Expand Up @@ -184,6 +185,13 @@ class TimelineMediaPreviewController: QLPreviewController {

private func handleFileLoaded(itemID: TimelineItemIdentifier.EventOrTransactionID) {
guard (currentPreviewItem as? TimelineMediaPreviewItem.Media)?.id == itemID else { return }

// There's a bug where refreshCurrentPreviewItem completely breaks the QLPreviewController
// if it's called whilst swiping between items. So don't let that happen.
if let scrollView = pageScrollView, scrollView.isDragging || scrollView.isDecelerating {
return
}

refreshCurrentPreviewItem()
}

Expand Down

0 comments on commit d7e39f1

Please sign in to comment.