mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 13:37:11 +00:00
Fix a bug where the preview controller breaks when swiping quickly. (#3750)
This commit is contained in:
parent
ddaf41cfca
commit
b284aa8a07
@ -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.firstScrollView() }
|
||||
private var captionView: UIView { captionHostingController.view }
|
||||
|
||||
override var overrideUserInterfaceStyle: UIUserInterfaceStyle {
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -336,6 +344,19 @@ private struct DownloadIndicatorView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension UIView {
|
||||
func firstScrollView() -> UIScrollView? {
|
||||
for view in subviews {
|
||||
if let scrollView = view as? UIScrollView ?? view.firstScrollView() {
|
||||
return scrollView
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private extension UISheetPresentationController.Detent {
|
||||
static func height(_ height: CGFloat) -> UISheetPresentationController.Detent {
|
||||
.custom { _ in height }
|
||||
|
Loading…
x
Reference in New Issue
Block a user