Compare commits

...

4 Commits

7 changed files with 47 additions and 11 deletions

View File

@ -52,6 +52,9 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans
appliedSourceToDestTransform = false
}
to.view.frame = container.bounds
from.view.frame = container.bounds
let content = itemViewController.takeContent()
content.view.translatesAutoresizingMaskIntoConstraints = true
content.view.layer.masksToBounds = true
@ -112,6 +115,8 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans
return
}
toVC.view.frame = transitionContext.containerView.bounds
fromVC.view.frame = transitionContext.containerView.bounds
transitionContext.containerView.addSubview(toVC.view)
transitionContext.containerView.addSubview(fromVC.view)

View File

@ -109,8 +109,6 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
itemViewController.addContent()
transitionContext.completeTransition(true)
to.presentationAnimationCompleted()
}
animator.startAnimation()
@ -121,8 +119,9 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
return
}
transitionContext.containerView.addSubview(to.view)
to.view.alpha = 0
to.view.frame = transitionContext.containerView.bounds
transitionContext.containerView.addSubview(to.view)
let duration = transitionDuration(using: transitionContext)
let animator = UIViewPropertyAnimator(duration: duration, curve: .easeInOut)
@ -131,8 +130,6 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
}
animator.addCompletion { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
to.presentationAnimationCompleted()
}
animator.startAnimation()
}

View File

@ -68,6 +68,17 @@ public class GalleryViewController: UIPageViewController {
setViewControllers([makeItemVC(index: initialItemIndex)], direction: .forward, animated: false)
}
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if animated {
// Wait until the transition is no longer in-progress, otherwise things will just get deferred again.
DispatchQueue.main.async {
self.presentationAnimationCompleted()
}
}
}
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

View File

@ -15,10 +15,12 @@ import AVFoundation
class StatusAttachmentsGalleryDataSource: GalleryDataSource {
let attachments: [Attachment]
let sourceViews: NSHashTable<AttachmentView>
weak var moreView: UIView?
init(attachments: [Attachment], sourceViews: NSHashTable<AttachmentView>) {
init(attachments: [Attachment], sourceViews: NSHashTable<AttachmentView>, moreView: UIView?) {
self.attachments = attachments
self.sourceViews = sourceViews
self.moreView = moreView
}
func galleryItemsCount() -> Int {
@ -39,6 +41,21 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource {
// TODO: if automatically play gifs is off, this will start the source view playing too
gifController: view.gifController
)
} else if let entry = ImageCache.attachments.get(attachment.url, loadOriginal: true) {
let gifController: GIFController? =
if attachment.url.pathExtension == "gif",
let data = entry.data {
GIFController(gifData: data)
} else {
nil
}
return ImageGalleryContentViewController(
url: attachment.url,
caption: attachment.description,
originalData: entry.data,
image: entry.image,
gifController: gifController
)
} else {
return LoadingGalleryContentViewController {
let (data, image) = await ImageCache.attachments.get(attachment.url, loadOriginal: true)
@ -92,8 +109,12 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource {
}
func galleryContentTransitionSourceView(forItemAt index: Int) -> UIView? {
let attachment = attachments[index]
return attachmentView(for: attachment)
if attachments.count > 4 && index >= 3 {
return moreView
} else {
let attachment = attachments[index]
return attachmentView(for: attachment)
}
}
func galleryApplicationActivities(forItemAt index: Int) -> [UIActivity]? {

View File

@ -238,7 +238,8 @@ extension StatusEditCollectionViewCell: AttachmentViewDelegate {
func attachmentViewGallery(startingAt index: Int) -> UIViewController? {
let attachments = attachmentsView.attachments!
let sourceViews = attachmentsView.attachmentViews.copy() as! NSHashTable<AttachmentView>
return GalleryVC.GalleryViewController(dataSource: StatusAttachmentsGalleryDataSource(attachments: attachments, sourceViews: sourceViews), initialItemIndex: index)
let dataSource = StatusAttachmentsGalleryDataSource(attachments: attachments, sourceViews: sourceViews, moreView: attachmentsView.moreView)
return GalleryVC.GalleryViewController(dataSource: dataSource, initialItemIndex: index)
}
func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {

View File

@ -18,7 +18,7 @@ class AttachmentsContainerView: UIView {
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
let attachmentStacks: NSHashTable<UIStackView> = .weakObjects()
var moreView: UIView?
private(set) var moreView: UIView?
private var aspectRatioConstraint: NSLayoutConstraint?
private(set) var aspectRatio: CGFloat = 16/9 {
didSet {

View File

@ -334,7 +334,8 @@ extension StatusCollectionViewCell {
return nil
}
let sourceViews = attachmentsView.attachmentViews.copy() as! NSHashTable<AttachmentView>
return GalleryVC.GalleryViewController(dataSource: StatusAttachmentsGalleryDataSource(attachments: status.attachments, sourceViews: sourceViews), initialItemIndex: index)
let dataSource = StatusAttachmentsGalleryDataSource(attachments: status.attachments, sourceViews: sourceViews, moreView: attachmentsView.moreView)
return GalleryVC.GalleryViewController(dataSource: dataSource, initialItemIndex: index)
}
func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {