Show label when attachments are hidden in timelines

This commit is contained in:
Shadowfacts 2023-12-04 16:38:04 -05:00
parent 108a02826f
commit 141e8b96a5
4 changed files with 57 additions and 17 deletions

View File

@ -192,6 +192,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
// separate method because InstanceTimelineViewController needs to be able to customize it
func configureStatusCell(_ cell: TimelineStatusCollectionViewCell, id: String, state: CollapseState, filterResult: Filterer.Result, precomputedContent: NSAttributedString?) {
cell.delegate = self
cell.showAttachmentsInline = Preferences.shared.showAttachmentsInTimeline
if case .home = timeline {
cell.showFollowedHashtags = true
} else {

View File

@ -30,8 +30,8 @@ class AttachmentsContainerView: UIView {
}
}
var blurView: UIVisualEffectView?
var hideButtonView: UIVisualEffectView?
private var blurView: UIVisualEffectView?
private var hideButtonView: UIVisualEffectView?
var contentHidden: Bool! {
didSet {
guard let blurView = blurView,
@ -42,6 +42,8 @@ class AttachmentsContainerView: UIView {
}
}
private var label: UILabel?
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
@ -67,22 +69,25 @@ class AttachmentsContainerView: UIView {
// MARK: - User Interaface
func updateUI(attachments: [Attachment]) {
func updateUI(attachments: [Attachment], labelOnly: Bool = false) {
let newTokens = attachments.map { AttachmentToken(attachment: $0) }
guard !labelOnly else {
self.attachments = attachments
self.attachmentTokens = newTokens
updateLabel(attachments: attachments)
return
}
guard self.attachmentTokens != newTokens else {
self.isHidden = attachments.isEmpty
return
}
self.attachments = attachments
self.attachmentTokens = newTokens
attachmentViews.allObjects.forEach { $0.removeFromSuperview() }
attachmentViews.removeAllObjects()
attachmentStacks.allObjects.forEach { $0.removeFromSuperview() }
attachmentStacks.removeAllObjects()
moreView?.removeFromSuperview()
removeAttachmentViews()
hideButtonView?.isHidden = false
var accessibilityElements = [Any]()
@ -285,6 +290,14 @@ class AttachmentsContainerView: UIView {
self.accessibilityElements = accessibilityElements
}
private func removeAttachmentViews() {
attachmentViews.allObjects.forEach { $0.removeFromSuperview() }
attachmentViews.removeAllObjects()
attachmentStacks.allObjects.forEach { $0.removeFromSuperview() }
attachmentStacks.removeAllObjects()
moreView?.removeFromSuperview()
}
private func createAttachmentView(index: Int, hSize: RelativeSize, vSize: RelativeSize) -> AttachmentView {
let attachmentView = AttachmentView(attachment: attachments[index], index: index)
attachmentView.delegate = delegate
@ -397,6 +410,35 @@ class AttachmentsContainerView: UIView {
])
}
private func updateLabel(attachments: [Attachment]) {
removeAttachmentViews()
blurView?.isHidden = true
hideButtonView?.isHidden = true
aspectRatioConstraint?.isActive = false
if label == nil {
if attachments.isEmpty {
accessibilityElements = []
return
}
label = UILabel()
label!.font = .preferredFont(forTextStyle: .body)
label!.adjustsFontForContentSizeCategory = true
label!.textColor = .secondaryLabel
label!.translatesAutoresizingMaskIntoConstraints = false
addSubview(label!)
NSLayoutConstraint.activate([
label!.leadingAnchor.constraint(equalTo: leadingAnchor),
label!.trailingAnchor.constraint(equalTo: trailingAnchor),
label!.topAnchor.constraint(equalTo: topAnchor),
label!.bottomAnchor.constraint(equalTo: bottomAnchor),
])
}
label!.text = "\(attachments.count) attachment\(attachments.count == 1 ? "" : "s")"
accessibilityElements = [label!]
}
// MARK: - Interaction
@objc func blurViewTapped() {

View File

@ -14,8 +14,8 @@ protocol StatusContentPollView: UIView {
class StatusContentContainer<ContentView: ContentTextView, PollView: StatusContentPollView>: UIView {
private var useTopSpacer = false
private let topSpacer = UIView().configure {
private let useTopSpacer: Bool
private lazy var topSpacer = UIView().configure {
$0.backgroundColor = .clear
// other 4pt is provided by this view's own spacing
$0.heightAnchor.constraint(equalToConstant: 4).isActive = true

View File

@ -297,6 +297,7 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
var showReplyIndicator = true
var showPinned: Bool = false
var showFollowedHashtags: Bool = false
var showAttachmentsInline = true
// alas these need to be internal so they're accessible from the protocol extensions
var statusID: String!
@ -646,12 +647,8 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
}
func updateAttachmentsUI(status: StatusMO) {
if Preferences.shared.showAttachmentsInTimeline {
attachmentsView.delegate = self
attachmentsView.updateUI(attachments: status.attachments)
} else {
attachmentsView.isHidden = true
}
attachmentsView.updateUI(attachments: status.attachments, labelOnly: !showAttachmentsInline)
}
func estimateContentHeight() -> CGFloat {