Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer activityIndicator stopAnimation #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ImageViewer/ImageViewerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public final class ImageViewerConfiguration {
public var image: UIImage?
public var imageView: UIImageView?
public var imageBlock: ImageBlock?
public var isPanSupported: ((UIInterfaceOrientation) -> Bool)?

public typealias ConfigurationClosure = (ImageViewerConfiguration) -> ()

Expand Down
13 changes: 11 additions & 2 deletions ImageViewer/ImageViewerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ private extension ImageViewerController {
guard let block = configuration?.imageBlock else { return }
activityIndicator.startAnimating()
block { [weak self] image in
defer {
DispatchQueue.main.async {
self?.activityIndicator.stopAnimating()
}
}
guard let image = image else { return }
DispatchQueue.main.async {
self?.activityIndicator.stopAnimating()
self?.imageView.image = image
}
}
Expand Down Expand Up @@ -116,8 +120,13 @@ private extension ImageViewerController {
}
}

private func isPanSupported(for orientation: UIInterfaceOrientation) -> Bool {
return configuration?.isPanSupported?(orientation) ?? true
}

@objc func imageViewPanned(_ recognizer: UIPanGestureRecognizer) {
guard transitionHandler != nil else { return }
guard transitionHandler != nil, isPanSupported(for: self.interfaceOrientation)
else { return }

let translation = recognizer.translation(in: imageView)
let velocity = recognizer.velocity(in: imageView)
Expand Down