Skip to content

Commit

Permalink
Fix the bug that the alert is not displayed when timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Oct 28, 2020
1 parent 01d3ee6 commit c6baed5
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFl
debugPrint("\(images) \(assets) \(isOriginal)")
}

ac.previewAssets(sender: self, assets: self.selectedAssets, index: indexPath.row, isOriginal: self.isOriginal, showBottomViewAndSelectBtn: false)
ac.previewAssets(sender: self, assets: self.selectedAssets, index: indexPath.row, isOriginal: self.isOriginal, showBottomViewAndSelectBtn: true)
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ZLPreviewImagePopAnimatedTransition.swift
// ZLPhotoPreviewAnimatedTransition.swift
// ZLPhotoBrowser
//
// Created by long on 2020/9/3.
Expand All @@ -26,8 +26,8 @@

import UIKit

class ZLPreviewImagePopAnimatedTransition: NSObject, UIViewControllerAnimatedTransitioning {

class ZLPhotoPreviewAnimatedTransition: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.25
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ZLPreviewImagePopInteractiveTransition.swift
// ZLPhotoPreviewPopInteractiveTransition.swift
// ZLPhotoBrowser
//
// Created by long on 2020/9/3.
Expand All @@ -26,7 +26,7 @@

import UIKit

class ZLPreviewImagePopInteractiveTransition: UIPercentDrivenInteractiveTransition {
class ZLPhotoPreviewPopInteractiveTransition: UIPercentDrivenInteractiveTransition {

weak var transitionContext: UIViewControllerContextTransitioning?

Expand Down
14 changes: 7 additions & 7 deletions Sources/General/ZLImagePreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class ZLImagePreviewController: UIViewController {

var selectStatus: [Bool]

let urlType: ( (URL) -> ZLURLType )
let urlType: ( (URL) -> ZLURLType )?

let urlImageLoader: ( (URL, UIImageView, @escaping ( (CGFloat) -> Void ), @escaping ( () -> Void )) -> Void )
let urlImageLoader: ( (URL, UIImageView, @escaping ( (CGFloat) -> Void ), @escaping ( () -> Void )) -> Void )?

let showSelectBtn: Bool

Expand Down Expand Up @@ -92,14 +92,14 @@ public class ZLImagePreviewController: UIViewController {
/// - urlType: Tell me the url is image or video.
/// - urlImageLoader: Call when cell will display, cell will layout after callback when image load finish. The first block is progress callback, second is load finish callback.
///
@objc public init(datas: [Any], index: Int = 0, showSelectBtn: Bool = true, urlType: @escaping ( (URL) -> ZLURLType ), urlImageLoader: @escaping ( (URL, UIImageView, @escaping ( (CGFloat) -> Void ), @escaping ( () -> Void )) -> Void ) ) {
@objc public init(datas: [Any], index: Int = 0, showSelectBtn: Bool = true, urlType: ( (URL) -> ZLURLType )? = nil, urlImageLoader: ( (URL, UIImageView, @escaping ( (CGFloat) -> Void ), @escaping ( () -> Void )) -> Void )? = nil) {
let filterDatas = datas.filter { (obj) -> Bool in
return obj is PHAsset || obj is UIImage || obj is URL
}
self.datas = filterDatas
self.selectStatus = Array(repeating: true, count: filterDatas.count)
self.currentIndex = index
self.indexBeforOrientationChanged = index
self.currentIndex = index >= filterDatas.count ? 0 : index
self.indexBeforOrientationChanged = self.currentIndex
self.showSelectBtn = showSelectBtn
self.urlType = urlType
self.urlImageLoader = urlImageLoader
Expand Down Expand Up @@ -447,12 +447,12 @@ extension ZLImagePreviewController: UICollectionViewDataSource, UICollectionView

baseCell = cell
} else if let url = obj as? URL {
let type = self.urlType(url)
let type = self.urlType?(url) ?? ZLURLType.image
if type == .image {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ZLNetImagePreviewCell.zl_identifier(), for: indexPath) as! ZLNetImagePreviewCell
cell.image = nil

self.urlImageLoader(url, cell.preview.imageView, { [weak cell] (progress) in
self.urlImageLoader?(url, cell.preview.imageView, { [weak cell] (progress) in
DispatchQueue.main.async {
cell?.progress = progress
}
Expand Down
6 changes: 2 additions & 4 deletions Sources/General/ZLPhotoConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ public class ZLPhotoConfiguration: NSObject {

@objc public var allowSelectVideo = true

/// Allow select Gif, it only controls whether it can be
/// selected, and does not control whether it is displayed.
/// Allow select Gif, it only controls whether it is displayed in Gif form.
/// If value is false, the Gif logo is not displayed.
@objc public var allowSelectGif = true

/// Allow select LivePhoto, it only controls whether it can be
/// selected, and does not control whether it is displayed.
/// Allow select LivePhoto, it only controls whether it is displayed in LivePhoto form.
/// If value is false, the LivePhoto logo is not displayed.
@objc public var allowSelectLivePhoto = false

Expand Down
11 changes: 6 additions & 5 deletions Sources/General/ZLPhotoPreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ZLPhotoPreviewController: UIViewController {

var hideNavView = false

var popInteractiveTransition: ZLPreviewImagePopInteractiveTransition?
var popInteractiveTransition: ZLPhotoPreviewPopInteractiveTransition?

/// 是否在点击确定时候,当未选择任何照片时候,自动选择当前index的照片
var autoSelectCurrentIfNotSelectAnyone = true
Expand Down Expand Up @@ -322,7 +322,7 @@ class ZLPhotoPreviewController: UIViewController {
// 仅有当前vc一个时候,说明不是从相册进入,不添加交互动画
return
}
self.popInteractiveTransition = ZLPreviewImagePopInteractiveTransition(viewController: self)
self.popInteractiveTransition = ZLPhotoPreviewPopInteractiveTransition(viewController: self)
self.popInteractiveTransition?.shouldStartTransition = { [weak self] (point) -> Bool in
guard let `self` = self else { return false }
if !self.hideNavView && (self.navView.frame.contains(point) || self.bottomView.frame.contains(point)) {
Expand Down Expand Up @@ -478,7 +478,8 @@ class ZLPhotoPreviewController: UIViewController {
} else if model.type == .video || config.allowEditVideo {
var requestAvAssetID: PHImageRequestID?
hud.show(timeout: 15)
hud.timeoutBlock = {
hud.timeoutBlock = { [weak self] in
showAlertView(localLanguageTextValue(.timeout), self)
if let _ = requestAvAssetID {
PHImageManager.default().cancelImageRequest(requestAvAssetID!)
}
Expand Down Expand Up @@ -556,7 +557,7 @@ class ZLPhotoPreviewController: UIViewController {
}
}
self.navView.isHidden = self.hideNavView
self.bottomView.isHidden = self.hideNavView
self.bottomView.isHidden = self.showBottomViewAndSelectBtn ? self.hideNavView : true
}

func showEditImageVC(image: UIImage) {
Expand Down Expand Up @@ -608,7 +609,7 @@ extension ZLPhotoPreviewController: UINavigationControllerDelegate {
if operation == .push {
return nil
}
return self.popInteractiveTransition?.interactive == true ? ZLPreviewImagePopAnimatedTransition() : nil
return self.popInteractiveTransition?.interactive == true ? ZLPhotoPreviewAnimatedTransition() : nil
}

func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
Expand Down
9 changes: 5 additions & 4 deletions Sources/General/ZLPhotoPreviewSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ public class ZLPhotoPreviewSheet: UIView {
let hud = ZLProgressHUD(style: ZLPhotoConfiguration.default().hudStyle)

var timeout = false
hud.timeoutBlock = {
showAlertView(localLanguageTextValue(.timeout), self.sender)
self.fetchImageQueue.cancelAllOperations()
hud.timeoutBlock = { [weak self] in
timeout = true
showAlertView(localLanguageTextValue(.timeout), viewController ?? self?.sender)
self?.fetchImageQueue.cancelAllOperations()
}

hud.show(timeout: ZLPhotoConfiguration.default().timeout)
Expand Down Expand Up @@ -627,7 +627,8 @@ public class ZLPhotoPreviewSheet: UIView {
var requestAvAssetID: PHImageRequestID?

hud.show(timeout: 15)
hud.timeoutBlock = {
hud.timeoutBlock = { [weak self] in
showAlertView(localLanguageTextValue(.timeout), self?.sender)
if let _ = requestAvAssetID {
PHImageManager.default().cancelImageRequest(requestAvAssetID!)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/General/ZLProgressHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public class ZLProgressHUD: UIView {
}

@objc func timeout(_ timer: Timer) {
self.timeoutBlock?()
self.hide()
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/General/ZLThumbnailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ class ZLThumbnailViewController: UIViewController {
var requestAvAssetID: PHImageRequestID?

hud.show(timeout: 15)
hud.timeoutBlock = {
hud.timeoutBlock = { [weak self] in
showAlertView(localLanguageTextValue(.timeout), self)
if let _ = requestAvAssetID {
PHImageManager.default().cancelImageRequest(requestAvAssetID!)
}
Expand Down
16 changes: 8 additions & 8 deletions ZLPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
E4CF57EC24EA63BA00BEBFC6 /* ZLProgressHUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4CF57EB24EA63BA00BEBFC6 /* ZLProgressHUD.swift */; };
E4CF57EE24EA73EF00BEBFC6 /* UIControl+ZLPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4CF57ED24EA73EF00BEBFC6 /* UIControl+ZLPhotoBrowser.swift */; };
E4CF57F024EA923C00BEBFC6 /* ZLLanguageDefine.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4CF57EF24EA923C00BEBFC6 /* ZLLanguageDefine.swift */; };
E4D046F02500A341000BAEC2 /* ZLPreviewImagePopAnimatedTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4D046EF2500A341000BAEC2 /* ZLPreviewImagePopAnimatedTransition.swift */; };
E4D046F22500A361000BAEC2 /* ZLPreviewImagePopInteractiveTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4D046F12500A361000BAEC2 /* ZLPreviewImagePopInteractiveTransition.swift */; };
E4D046F02500A341000BAEC2 /* ZLPhotoPreviewAnimatedTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4D046EF2500A341000BAEC2 /* ZLPhotoPreviewAnimatedTransition.swift */; };
E4D046F22500A361000BAEC2 /* ZLPhotoPreviewPopInteractiveTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4D046F12500A361000BAEC2 /* ZLPhotoPreviewPopInteractiveTransition.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -89,8 +89,8 @@
E4CF57EB24EA63BA00BEBFC6 /* ZLProgressHUD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLProgressHUD.swift; sourceTree = "<group>"; };
E4CF57ED24EA73EF00BEBFC6 /* UIControl+ZLPhotoBrowser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIControl+ZLPhotoBrowser.swift"; sourceTree = "<group>"; };
E4CF57EF24EA923C00BEBFC6 /* ZLLanguageDefine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLLanguageDefine.swift; sourceTree = "<group>"; };
E4D046EF2500A341000BAEC2 /* ZLPreviewImagePopAnimatedTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPreviewImagePopAnimatedTransition.swift; sourceTree = "<group>"; };
E4D046F12500A361000BAEC2 /* ZLPreviewImagePopInteractiveTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPreviewImagePopInteractiveTransition.swift; sourceTree = "<group>"; };
E4D046EF2500A341000BAEC2 /* ZLPhotoPreviewAnimatedTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPhotoPreviewAnimatedTransition.swift; sourceTree = "<group>"; };
E4D046F12500A361000BAEC2 /* ZLPhotoPreviewPopInteractiveTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPhotoPreviewPopInteractiveTransition.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -147,8 +147,8 @@
E4C911CB24E286530061DA40 /* Animation */ = {
isa = PBXGroup;
children = (
E4D046EF2500A341000BAEC2 /* ZLPreviewImagePopAnimatedTransition.swift */,
E4D046F12500A361000BAEC2 /* ZLPreviewImagePopInteractiveTransition.swift */,
E4D046EF2500A341000BAEC2 /* ZLPhotoPreviewAnimatedTransition.swift */,
E4D046F12500A361000BAEC2 /* ZLPhotoPreviewPopInteractiveTransition.swift */,
E48E52D42507297500619AED /* ZLClipImageDismissAnimatedTransition.swift */,
);
path = Animation;
Expand Down Expand Up @@ -308,7 +308,7 @@
E4CF57EC24EA63BA00BEBFC6 /* ZLProgressHUD.swift in Sources */,
E4C911DC24E2A69B0061DA40 /* ZLPhotoModel.swift in Sources */,
E417AC0224F63E7E00EDDCD2 /* ZLEditImageViewController.swift in Sources */,
E4D046F22500A361000BAEC2 /* ZLPreviewImagePopInteractiveTransition.swift in Sources */,
E4D046F22500A361000BAEC2 /* ZLPhotoPreviewPopInteractiveTransition.swift in Sources */,
E462466224EBF06F00EF6C57 /* String+ZLPhotoBrowser.swift in Sources */,
E462466424EBF36F00EF6C57 /* UIColor+ZLPhotoBrowser.swift in Sources */,
E462467624EF6A7D00EF6C57 /* ZLPhotoPreviewCell.swift in Sources */,
Expand All @@ -318,7 +318,7 @@
E492ABEB24E53575005E1BD5 /* Cell+ZLPhotoBrowser.swift in Sources */,
E4CF57EE24EA73EF00BEBFC6 /* UIControl+ZLPhotoBrowser.swift in Sources */,
E49BD1FB24E3D515005D7DFB /* Bundle+ZLPhotoBrowser.swift in Sources */,
E4D046F02500A341000BAEC2 /* ZLPreviewImagePopAnimatedTransition.swift in Sources */,
E4D046F02500A341000BAEC2 /* ZLPhotoPreviewAnimatedTransition.swift in Sources */,
E462465A24EB9ABF00EF6C57 /* ZLFetchImageOperation.swift in Sources */,
E4C911DE24E2AA950061DA40 /* ZLAlbumListModel.swift in Sources */,
E49BD1F724E3CD9E005D7DFB /* ZLThumbnailPhotoCell.swift in Sources */,
Expand Down

0 comments on commit c6baed5

Please sign in to comment.