Compare commits

..

No commits in common. "f2e08e96f3347c53528f316e7ebb451b7e109ebe" and "26c99a1a35a81d7f53689f1cc493f444a17130df" have entirely different histories.

10 changed files with 36 additions and 60 deletions

View File

@ -10,22 +10,20 @@ import UIKit
extension UIViewController: UIViewControllerTransitioningDelegate {
public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if let presented = presented as? LargeImageViewController,
presented.sourceInfo?.image != nil {
if presented is LargeImageViewController {
return LargeImageExpandAnimationController()
} else if let presented = presented as? GalleryViewController,
presented.sourcesInfo[presented.startIndex]?.image != nil {
presented.sourcesInfo[presented.startIndex] != nil {
return GalleryExpandAnimationController()
}
return nil
}
public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if let dismissed = dismissed as? LargeImageViewController,
dismissed.imageForDismissalAnimation() != nil {
if let dismissed = dismissed as? LargeImageViewController {
return LargeImageShrinkAnimationController(interactionController: dismissed.dismissInteractionController)
} else if let dismissed = dismissed as? GalleryViewController,
dismissed.imageForDismissalAnimation() != nil {
dismissed.sourcesInfo[dismissed.currentIndex] != nil {
return GalleryShrinkAnimationController(interactionController: dismissed.dismissInteractionController)
}
return nil

View File

@ -48,9 +48,6 @@ class AttachmentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .dark
view.backgroundColor = .black
if let data = ImageCache.attachments.get(attachment.url) {
createLargeImage(data: data)
} else {

View File

@ -78,8 +78,6 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
self.dataSource = self
self.delegate = self
overrideUserInterfaceStyle = .dark
dismissInteractionController = LargeImageInteractionController(viewController: self)
}
@ -96,14 +94,6 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
vc.player?.play()
}
}
func imageForDismissalAnimation() -> UIImage? {
if let sourceImage = sourcesInfo[currentIndex]?.image {
return sourceImage
} else {
return (pages[currentIndex] as? AttachmentViewController)?.largeImageVC?.image
}
}
// MARK: - Page View Controller Data Source

View File

@ -20,19 +20,17 @@ class GalleryExpandAnimationController: NSObject, UIViewControllerAnimatedTransi
return
}
let containerView = transitionContext.containerView
containerView.addSubview(toVC.view)
let finalVCFrame = transitionContext.finalFrame(for: toVC)
guard let sourceInfo = toVC.sourcesInfo[toVC.startIndex],
let image = sourceInfo.image else {
toVC.view.frame = finalVCFrame
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
guard let (image, sourceFrame, sourceCornerRadius) = toVC.sourcesInfo[toVC.startIndex] else {
toVC.view.frame = finalVCFrame
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
}
let attachment = toVC.attachments[toVC.startIndex]
let containerView = transitionContext.containerView
let ratio = image.size.width / image.size.height
var width = finalVCFrame.width
var height = width / ratio
@ -44,20 +42,21 @@ class GalleryExpandAnimationController: NSObject, UIViewControllerAnimatedTransi
}
let finalFrame = CGRect(x: finalVCFrame.midX - width / 2, y: finalVCFrame.midY - height / 2, width: width, height: height)
let imageView = GIFImageView(frame: sourceInfo.frame)
let imageView = GIFImageView(frame: sourceFrame)
imageView.image = image
if attachment.url.pathExtension == "gif",
let data = ImageCache.attachments.get(attachment.url) {
imageView.animate(withGIFData: data)
}
imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = sourceInfo.cornerRadius
imageView.layer.cornerRadius = sourceCornerRadius
imageView.layer.masksToBounds = true
let blackView = UIView(frame: finalVCFrame)
blackView.backgroundColor = .black
blackView.alpha = 0
containerView.addSubview(toVC.view)
containerView.addSubview(blackView)
containerView.addSubview(imageView)

View File

@ -26,8 +26,7 @@ class GalleryShrinkAnimationController: NSObject, UIViewControllerAnimatedTransi
return
}
guard let sourceInfo = fromVC.sourcesInfo[fromVC.currentIndex],
let image = fromVC.imageForDismissalAnimation() else {
guard let (image, sourceFrame, sourceCornerRadius) = fromVC.sourcesInfo[fromVC.currentIndex] else {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
}
@ -67,8 +66,8 @@ class GalleryShrinkAnimationController: NSObject, UIViewControllerAnimatedTransi
let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: {
imageView.frame = sourceInfo.frame
imageView.layer.cornerRadius = sourceInfo.cornerRadius
imageView.frame = sourceFrame
imageView.layer.cornerRadius = sourceCornerRadius
blackView.alpha = 0
}, completion: { _ in
blackView.removeFromSuperview()

View File

@ -13,7 +13,7 @@ import Gifu
class LargeImageViewController: UIViewController, UIScrollViewDelegate {
typealias SourceInfo = (image: UIImage?, frame: CGRect, cornerRadius: CGFloat)
typealias SourceInfo = (image: UIImage, frame: CGRect, cornerRadius: CGFloat)
var sourceInfo: SourceInfo?
var dismissInteractionController: LargeImageInteractionController?
@ -132,10 +132,6 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
}
}
}
func imageForDismissalAnimation() -> UIImage? {
return sourceInfo?.image ?? image
}
func setControlsVisible(_ controlsVisible: Bool, animated: Bool) {
self.controlsVisible = controlsVisible

View File

@ -21,35 +21,33 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra
return
}
let containerView = transitionContext.containerView
containerView.addSubview(toVC.view)
let finalVCFrame = transitionContext.finalFrame(for: toVC)
guard let sourceInfo = toVC.sourceInfo,
let image = sourceInfo.image else {
toVC.view.frame = finalVCFrame
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
guard let (image, originFrame, originCornerRadius) = toVC.sourceInfo else {
toVC.view.frame = finalVCFrame
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
}
let containerView = transitionContext.containerView
let ratio = image.size.width / image.size.height
let width = finalVCFrame.width
let height = width / ratio
let finalFrame = CGRect(x: finalVCFrame.midX - width / 2, y: finalVCFrame.midY - height / 2, width: width, height: height)
let imageView = GIFImageView(frame: sourceInfo.frame)
imageView.image = image
let imageView = GIFImageView(frame: originFrame)
imageView.image = toVC.imageView.image!
if let gifData = toVC.gifData {
imageView.animate(withGIFData: gifData)
}
imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = sourceInfo.cornerRadius
imageView.layer.cornerRadius = originCornerRadius
imageView.layer.masksToBounds = true
let blackView = UIView(frame: finalVCFrame)
blackView.backgroundColor = .black
blackView.alpha = 0
containerView.addSubview(toVC.view)
containerView.addSubview(blackView)
containerView.addSubview(imageView)

View File

@ -27,12 +27,11 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra
return
}
guard let sourceInfo = fromVC.sourceInfo,
let image = fromVC.imageForDismissalAnimation() else {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
guard let (image, finalFrame, finalCornerRadius) = fromVC.sourceInfo else {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
return
}
let originalVCFrame = fromVC.view.frame
let containerView = transitionContext.containerView
@ -60,8 +59,8 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra
let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: {
imageView.frame = sourceInfo.frame
imageView.layer.cornerRadius = sourceInfo.cornerRadius
imageView.frame = finalFrame
imageView.layer.cornerRadius = finalCornerRadius
blackView.alpha = 0
}, completion: { _ in
blackView.removeFromSuperview()

View File

@ -16,7 +16,7 @@ class LoadingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .clear
view.backgroundColor = .systemBackground
activityIndicator = UIActivityIndicatorView(style: .large)
activityIndicator.color = .secondaryLabel

View File

@ -159,7 +159,7 @@ extension TuskerNavigationDelegate where Self: UIViewController {
let y = sourceFrame.minY * scale - scrollView.contentOffset.y + scrollView.frame.minY
sourceFrame = CGRect(x: x, y: y, width: width, height: height)
}
return (image: sourceView.image, frame: sourceFrame, cornerRadius: sourceView.layer.cornerRadius)
return (image: sourceView.image!, frame: sourceFrame, cornerRadius: sourceView.layer.cornerRadius)
}
func largeImage(_ image: UIImage, description: String?, sourceView: UIImageView) -> LargeImageViewController {