Skip to content

Commit

Permalink
Enables tapping Next before high res preview is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
s4cha committed Jan 8, 2020
1 parent 34b41d2 commit 7c2bb71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Source/Pages/Gallery/YPLibraryVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Source/Pages/Gallery/YPLibraryViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion Source/YPPickerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 7c2bb71

Please sign in to comment.