Show label when attachments are hidden in timelines
This commit is contained in:
parent
108a02826f
commit
141e8b96a5
|
@ -192,6 +192,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
// separate method because InstanceTimelineViewController needs to be able to customize it
|
// separate method because InstanceTimelineViewController needs to be able to customize it
|
||||||
func configureStatusCell(_ cell: TimelineStatusCollectionViewCell, id: String, state: CollapseState, filterResult: Filterer.Result, precomputedContent: NSAttributedString?) {
|
func configureStatusCell(_ cell: TimelineStatusCollectionViewCell, id: String, state: CollapseState, filterResult: Filterer.Result, precomputedContent: NSAttributedString?) {
|
||||||
cell.delegate = self
|
cell.delegate = self
|
||||||
|
cell.showAttachmentsInline = Preferences.shared.showAttachmentsInTimeline
|
||||||
if case .home = timeline {
|
if case .home = timeline {
|
||||||
cell.showFollowedHashtags = true
|
cell.showFollowedHashtags = true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,8 +30,8 @@ class AttachmentsContainerView: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var blurView: UIVisualEffectView?
|
private var blurView: UIVisualEffectView?
|
||||||
var hideButtonView: UIVisualEffectView?
|
private var hideButtonView: UIVisualEffectView?
|
||||||
var contentHidden: Bool! {
|
var contentHidden: Bool! {
|
||||||
didSet {
|
didSet {
|
||||||
guard let blurView = blurView,
|
guard let blurView = blurView,
|
||||||
|
@ -42,6 +42,8 @@ class AttachmentsContainerView: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var label: UILabel?
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
commonInit()
|
commonInit()
|
||||||
|
@ -67,22 +69,25 @@ class AttachmentsContainerView: UIView {
|
||||||
|
|
||||||
// MARK: - User Interaface
|
// MARK: - User Interaface
|
||||||
|
|
||||||
func updateUI(attachments: [Attachment]) {
|
func updateUI(attachments: [Attachment], labelOnly: Bool = false) {
|
||||||
let newTokens = attachments.map { AttachmentToken(attachment: $0) }
|
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 {
|
guard self.attachmentTokens != newTokens else {
|
||||||
self.isHidden = attachments.isEmpty
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.attachments = attachments
|
self.attachments = attachments
|
||||||
self.attachmentTokens = newTokens
|
self.attachmentTokens = newTokens
|
||||||
|
|
||||||
attachmentViews.allObjects.forEach { $0.removeFromSuperview() }
|
removeAttachmentViews()
|
||||||
attachmentViews.removeAllObjects()
|
hideButtonView?.isHidden = false
|
||||||
attachmentStacks.allObjects.forEach { $0.removeFromSuperview() }
|
|
||||||
attachmentStacks.removeAllObjects()
|
|
||||||
moreView?.removeFromSuperview()
|
|
||||||
|
|
||||||
var accessibilityElements = [Any]()
|
var accessibilityElements = [Any]()
|
||||||
|
|
||||||
|
@ -285,6 +290,14 @@ class AttachmentsContainerView: UIView {
|
||||||
self.accessibilityElements = accessibilityElements
|
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 {
|
private func createAttachmentView(index: Int, hSize: RelativeSize, vSize: RelativeSize) -> AttachmentView {
|
||||||
let attachmentView = AttachmentView(attachment: attachments[index], index: index)
|
let attachmentView = AttachmentView(attachment: attachments[index], index: index)
|
||||||
attachmentView.delegate = delegate
|
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
|
// MARK: - Interaction
|
||||||
|
|
||||||
@objc func blurViewTapped() {
|
@objc func blurViewTapped() {
|
||||||
|
|
|
@ -14,8 +14,8 @@ protocol StatusContentPollView: UIView {
|
||||||
|
|
||||||
class StatusContentContainer<ContentView: ContentTextView, PollView: StatusContentPollView>: UIView {
|
class StatusContentContainer<ContentView: ContentTextView, PollView: StatusContentPollView>: UIView {
|
||||||
|
|
||||||
private var useTopSpacer = false
|
private let useTopSpacer: Bool
|
||||||
private let topSpacer = UIView().configure {
|
private lazy var topSpacer = UIView().configure {
|
||||||
$0.backgroundColor = .clear
|
$0.backgroundColor = .clear
|
||||||
// other 4pt is provided by this view's own spacing
|
// other 4pt is provided by this view's own spacing
|
||||||
$0.heightAnchor.constraint(equalToConstant: 4).isActive = true
|
$0.heightAnchor.constraint(equalToConstant: 4).isActive = true
|
||||||
|
|
|
@ -297,6 +297,7 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
||||||
var showReplyIndicator = true
|
var showReplyIndicator = true
|
||||||
var showPinned: Bool = false
|
var showPinned: Bool = false
|
||||||
var showFollowedHashtags: Bool = false
|
var showFollowedHashtags: Bool = false
|
||||||
|
var showAttachmentsInline = true
|
||||||
|
|
||||||
// alas these need to be internal so they're accessible from the protocol extensions
|
// alas these need to be internal so they're accessible from the protocol extensions
|
||||||
var statusID: String!
|
var statusID: String!
|
||||||
|
@ -646,12 +647,8 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAttachmentsUI(status: StatusMO) {
|
func updateAttachmentsUI(status: StatusMO) {
|
||||||
if Preferences.shared.showAttachmentsInTimeline {
|
attachmentsView.delegate = self
|
||||||
attachmentsView.delegate = self
|
attachmentsView.updateUI(attachments: status.attachments, labelOnly: !showAttachmentsInline)
|
||||||
attachmentsView.updateUI(attachments: status.attachments)
|
|
||||||
} else {
|
|
||||||
attachmentsView.isHidden = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func estimateContentHeight() -> CGFloat {
|
func estimateContentHeight() -> CGFloat {
|
||||||
|
|
Loading…
Reference in New Issue