From 80f21cb2f18e3b817d3b92e754e33b0bc6f21efb Mon Sep 17 00:00:00 2001 From: Fahim Farook Date: Wed, 25 Jan 2023 17:06:47 +0400 Subject: [PATCH] Collapsible Table Cells * Fix the table cell instances to use the new collapsible button * Add accessibility label to StatusCollapseButton and change button to allow setting action --- .../Status/BaseStatusTableViewCell.swift | 42 ++----------------- .../Views/Status/StatusCollapseButton.swift | 7 +++- .../Status/TimelineStatusTableViewCell.swift | 2 + .../Status/TimelineStatusTableViewCell.xib | 32 +++----------- 4 files changed, 17 insertions(+), 66 deletions(-) diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 37f20974..c6c935eb 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -31,7 +31,7 @@ class BaseStatusTableViewCell: UITableViewCell { @IBOutlet weak var usernameLabel: UILabel! @IBOutlet weak var metaIndicatorsView: StatusMetaIndicatorsView! @IBOutlet weak var contentWarningLabel: EmojiLabel! - @IBOutlet weak var collapseButton: UIButton! + @IBOutlet weak var collapseButton: StatusCollapseButton! @IBOutlet weak var contentTextView: StatusContentTextView! @IBOutlet weak var cardView: StatusCardView! @IBOutlet weak var attachmentsView: AttachmentsContainerView! @@ -91,10 +91,7 @@ class BaseStatusTableViewCell: UITableViewCell { avatarImageView.addInteraction(UIDragInteraction(delegate: self)) attachmentsView.delegate = self - - collapseButton.layer.masksToBounds = true - collapseButton.layer.cornerRadius = 5 - + accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!, pollView!] moreButton.showsMenuAsPrimaryAction = true @@ -188,6 +185,7 @@ class BaseStatusTableViewCell: UITableViewCell { state.collapsed = false } } + collapseButton.title = statusState.reason collapsible = state.collapsible! setCollapsed(state.collapsed!, animated: false) } @@ -360,40 +358,6 @@ class BaseStatusTableViewCell: UITableViewCell { pollView.isHidden = pollView.poll == nil || collapsed let buttonImage = UIImage(systemName: collapsed ? "chevron.down" : "chevron.up")! - - if let buttonImageView = collapseButton.imageView { - collapseButton.setImage(buttonImage, for: .normal) - - if animated { - buttonImageView.layer.opacity = 0 - - // this whole hack is necessary because when just rotating buttonImageView, it moves to the left of the button and then animates back to the center - let imageView = UIImageView(image: buttonImageView.image) - imageView.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(imageView) - NSLayoutConstraint.activate([ - imageView.widthAnchor.constraint(equalTo: buttonImageView.widthAnchor), - imageView.heightAnchor.constraint(equalTo: buttonImageView.heightAnchor), - imageView.centerXAnchor.constraint(equalTo: collapseButton.centerXAnchor), - imageView.centerYAnchor.constraint(equalTo: collapseButton.centerYAnchor), - ]) - imageView.tintColor = .white - - UIView.animate(withDuration: 0.3, delay: 0) { - imageView.transform = CGAffineTransform(rotationAngle: .pi) - } completion: { _ in - imageView.removeFromSuperview() - buttonImageView.layer.opacity = 1 - } - } - } - - if collapsed { - collapseButton.accessibilityLabel = NSLocalizedString("Expand Status", comment: "expand status button accessibility label") - } else { - collapseButton.accessibilityLabel = NSLocalizedString("Collapse Status", comment: "collapse status button accessibility label") - } - } @IBAction func replyPressed() { diff --git a/Tusker/Views/Status/StatusCollapseButton.swift b/Tusker/Views/Status/StatusCollapseButton.swift index d4830170..3cfc74f4 100644 --- a/Tusker/Views/Status/StatusCollapseButton.swift +++ b/Tusker/Views/Status/StatusCollapseButton.swift @@ -9,6 +9,8 @@ import UIKit class StatusCollapseButton: UIView { + var action: (()->Void)! + var title: String { get { return lblTitle.text ?? "" @@ -18,7 +20,6 @@ class StatusCollapseButton: UIView { } } - private var action: (()->Void)! private var lblTitle = UILabel() private var imgView = UIImageView() private var isCollapsed = true @@ -35,6 +36,7 @@ class StatusCollapseButton: UIView { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) + setup() } override func touchesBegan(_ touches: Set, with event: UIEvent?) { @@ -52,8 +54,10 @@ class StatusCollapseButton: UIView { override func touchesEnded(_ touches: Set, with event: UIEvent?) { if isCollapsed { imgView.image = UIImage(systemName: "chevron.compact.up") + accessibilityLabel = NSLocalizedString("Collapse Status", comment: "collapse status button accessibility label") } else { imgView.image = UIImage(systemName: "chevron.compact.down") + accessibilityLabel = NSLocalizedString("Expand Status", comment: "expand status button accessibility label") } isCollapsed.toggle() action() @@ -64,6 +68,7 @@ class StatusCollapseButton: UIView { self.isUserInteractionEnabled = true layer.cornerRadius = 8 backgroundColor = .lightGray + accessibilityLabel = NSLocalizedString("Expand Status", comment: "expand status button accessibility label") // Title lblTitle.translatesAutoresizingMaskIntoConstraints = false lblTitle.textColor = .white diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 971aeac9..9a8c9ddc 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -83,6 +83,8 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { ]), size: 0) contentWarningLabel.adjustsFontForContentSizeCategory = true + collapseButton.action = collapseButtonPressed + contentTextView.defaultFont = UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 16)) contentTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 16, weight: .regular)) contentTextView.adjustsFontForContentSizeCategory = true diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.xib b/Tusker/Views/Status/TimelineStatusTableViewCell.xib index 1ce14e1d..45300c71 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.xib +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.xib @@ -103,28 +103,12 @@ - + + + + - + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. @@ -257,7 +241,7 @@ - + @@ -278,7 +262,6 @@ - @@ -295,8 +278,5 @@ - - -