mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Fix a bug where the preview controller breaks when swiping quickly. (#3750)
This commit is contained in:
@@ -25,6 +25,7 @@ class TimelineMediaPreviewController: QLPreviewController {
|
|||||||
|
|
||||||
private var navigationBar: UINavigationBar? { view.subviews.first?.subviews.first { $0 is UINavigationBar } as? UINavigationBar }
|
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 toolbar: UIToolbar? { view.subviews.first?.subviews.last { $0 is UIToolbar } as? UIToolbar }
|
||||||
|
private var pageScrollView: UIScrollView? { view.firstScrollView() }
|
||||||
private var captionView: UIView { captionHostingController.view }
|
private var captionView: UIView { captionHostingController.view }
|
||||||
|
|
||||||
override var overrideUserInterfaceStyle: UIUserInterfaceStyle {
|
override var overrideUserInterfaceStyle: UIUserInterfaceStyle {
|
||||||
@@ -184,6 +185,13 @@ class TimelineMediaPreviewController: QLPreviewController {
|
|||||||
|
|
||||||
private func handleFileLoaded(itemID: TimelineItemIdentifier.EventOrTransactionID) {
|
private func handleFileLoaded(itemID: TimelineItemIdentifier.EventOrTransactionID) {
|
||||||
guard (currentPreviewItem as? TimelineMediaPreviewItem.Media)?.id == itemID else { return }
|
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()
|
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 {
|
private extension UISheetPresentationController.Detent {
|
||||||
static func height(_ height: CGFloat) -> UISheetPresentationController.Detent {
|
static func height(_ height: CGFloat) -> UISheetPresentationController.Detent {
|
||||||
.custom { _ in height }
|
.custom { _ in height }
|
||||||
|
|||||||
Reference in New Issue
Block a user