Enable gallery interactive dismissal for statuses with >4 attachments

Closes #466
This commit is contained in:
Shadowfacts 2024-04-02 21:21:39 -04:00
parent ae7101bb30
commit 442f57bfc4
4 changed files with 14 additions and 6 deletions

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 {
@ -107,9 +109,13 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource {
}
func galleryContentTransitionSourceView(forItemAt index: Int) -> UIView? {
if attachments.count > 4 && index >= 3 {
return moreView
} else {
let attachment = attachments[index]
return attachmentView(for: attachment)
}
}
func galleryApplicationActivities(forItemAt index: Int) -> [UIActivity]? {
[SaveToPhotosActivity()]

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) {