From 7c2bb716b6f9a0b0e241eef329113134083e0bc8 Mon Sep 17 00:00:00 2001 From: S4cha Date: Wed, 8 Jan 2020 19:46:57 +0100 Subject: [PATCH] Enables tapping Next before high res preview is loaded --- Source/Pages/Gallery/YPLibraryVC.swift | 6 +++--- Source/Pages/Gallery/YPLibraryViewDelegate.swift | 3 ++- Source/YPPickerVC.swift | 9 ++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/Pages/Gallery/YPLibraryVC.swift b/Source/Pages/Gallery/YPLibraryVC.swift index b8b4c5542..9a0441ffe 100644 --- a/Source/Pages/Gallery/YPLibraryVC.swift +++ b/Source/Pages/Gallery/YPLibraryVC.swift @@ -312,7 +312,7 @@ public class YPLibraryVC: UIViewController, YPPermissionCheckable { func changeAsset(_ asset: PHAsset) { latestImageTapped = asset.localIdentifier - delegate?.libraryViewStartedLoading() + delegate?.libraryViewStartedLoadingImage() let completion = { (isLowResIntermediaryImage: Bool) in self.v.hideGrid() @@ -414,7 +414,7 @@ public class YPLibraryVC: UIViewController, YPPermissionCheckable { private func fetchImageAndCrop(for asset: PHAsset, withCropRect: CGRect? = nil, callback: @escaping (_ photo: UIImage, _ exif: [String : Any]) -> Void) { - delegate?.libraryViewStartedLoading() + delegate?.libraryViewDidTapNext() let cropRect = withCropRect ?? DispatchQueue.main.sync { v.currentCropRect() } let ts = targetSize(for: asset, cropRect: cropRect) mediaManager.imageManager?.fetchImage(for: asset, cropRect: cropRect, targetSize: ts, callback: callback) @@ -424,7 +424,7 @@ public class YPLibraryVC: UIViewController, YPPermissionCheckable { withCropRect: CGRect? = nil, callback: @escaping (_ videoURL: URL) -> Void) { if fitsVideoLengthLimits(asset: asset) == true { - delegate?.libraryViewStartedLoading() + delegate?.libraryViewDidTapNext() let normalizedCropRect = withCropRect ?? DispatchQueue.main.sync { v.currentCropRect() } let ts = targetSize(for: asset, cropRect: normalizedCropRect) let xCrop: CGFloat = normalizedCropRect.origin.x * CGFloat(asset.pixelWidth) diff --git a/Source/Pages/Gallery/YPLibraryViewDelegate.swift b/Source/Pages/Gallery/YPLibraryViewDelegate.swift index 8b50aac69..690062522 100644 --- a/Source/Pages/Gallery/YPLibraryViewDelegate.swift +++ b/Source/Pages/Gallery/YPLibraryViewDelegate.swift @@ -10,7 +10,8 @@ import Foundation @objc public protocol YPLibraryViewDelegate: class { - func libraryViewStartedLoading() + func libraryViewDidTapNext() + func libraryViewStartedLoadingImage() func libraryViewFinishedLoading() func libraryViewDidToggleMultipleSelection(enabled: Bool) func noPhotosForOptions() diff --git a/Source/YPPickerVC.swift b/Source/YPPickerVC.swift index 1910360f5..0c1e9f7ef 100644 --- a/Source/YPPickerVC.swift +++ b/Source/YPPickerVC.swift @@ -328,7 +328,7 @@ open class YPPickerVC: YPBottomPager, YPBottomPagerDelegate { extension YPPickerVC: YPLibraryViewDelegate { - public func libraryViewStartedLoading() { + public func libraryViewDidTapNext() { libraryVC?.isProcessing = true DispatchQueue.main.async { self.v.scrollView.isScrollEnabled = false @@ -337,6 +337,13 @@ extension YPPickerVC: YPLibraryViewDelegate { } } + public func libraryViewStartedLoadingImage() { + libraryVC?.isProcessing = true //TODO remove to enable changing selection while loading but needs cancelling previous image requests. + DispatchQueue.main.async { + self.libraryVC?.v.fadeInLoader() + } + } + public func libraryViewFinishedLoading() { libraryVC?.isProcessing = false DispatchQueue.main.async {