Enable gallery interactive dismissal for statuses with >4 attachments
Closes #466
This commit is contained in:
parent
ae7101bb30
commit
442f57bfc4
|
@ -15,10 +15,12 @@ import AVFoundation
|
||||||
class StatusAttachmentsGalleryDataSource: GalleryDataSource {
|
class StatusAttachmentsGalleryDataSource: GalleryDataSource {
|
||||||
let attachments: [Attachment]
|
let attachments: [Attachment]
|
||||||
let sourceViews: NSHashTable<AttachmentView>
|
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.attachments = attachments
|
||||||
self.sourceViews = sourceViews
|
self.sourceViews = sourceViews
|
||||||
|
self.moreView = moreView
|
||||||
}
|
}
|
||||||
|
|
||||||
func galleryItemsCount() -> Int {
|
func galleryItemsCount() -> Int {
|
||||||
|
@ -107,8 +109,12 @@ class StatusAttachmentsGalleryDataSource: GalleryDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func galleryContentTransitionSourceView(forItemAt index: Int) -> UIView? {
|
func galleryContentTransitionSourceView(forItemAt index: Int) -> UIView? {
|
||||||
let attachment = attachments[index]
|
if attachments.count > 4 && index >= 3 {
|
||||||
return attachmentView(for: attachment)
|
return moreView
|
||||||
|
} else {
|
||||||
|
let attachment = attachments[index]
|
||||||
|
return attachmentView(for: attachment)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func galleryApplicationActivities(forItemAt index: Int) -> [UIActivity]? {
|
func galleryApplicationActivities(forItemAt index: Int) -> [UIActivity]? {
|
||||||
|
|
|
@ -238,7 +238,8 @@ extension StatusEditCollectionViewCell: AttachmentViewDelegate {
|
||||||
func attachmentViewGallery(startingAt index: Int) -> UIViewController? {
|
func attachmentViewGallery(startingAt index: Int) -> UIViewController? {
|
||||||
let attachments = attachmentsView.attachments!
|
let attachments = attachmentsView.attachments!
|
||||||
let sourceViews = attachmentsView.attachmentViews.copy() as! NSHashTable<AttachmentView>
|
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) {
|
func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AttachmentsContainerView: UIView {
|
||||||
|
|
||||||
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
|
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
|
||||||
let attachmentStacks: NSHashTable<UIStackView> = .weakObjects()
|
let attachmentStacks: NSHashTable<UIStackView> = .weakObjects()
|
||||||
var moreView: UIView?
|
private(set) var moreView: UIView?
|
||||||
private var aspectRatioConstraint: NSLayoutConstraint?
|
private var aspectRatioConstraint: NSLayoutConstraint?
|
||||||
private(set) var aspectRatio: CGFloat = 16/9 {
|
private(set) var aspectRatio: CGFloat = 16/9 {
|
||||||
didSet {
|
didSet {
|
||||||
|
|
|
@ -334,7 +334,8 @@ extension StatusCollectionViewCell {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let sourceViews = attachmentsView.attachmentViews.copy() as! NSHashTable<AttachmentView>
|
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) {
|
func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {
|
||||||
|
|
Loading…
Reference in New Issue