From 4934a6e45c3350dc9b109823e07e33601664b369 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Fri, 5 Mar 2021 12:36:49 -0800 Subject: [PATCH] Label uncaptioned attachments --- Localizations/Localizable.strings | 1 + Metatext.xcodeproj/project.pbxproj | 2 ++ Views/UIKit/AttachmentView.swift | 19 ++++++++----------- Views/UIKit/AttachmentsView.swift | 1 - Views/UIKit/CapsuleLabel.swift | 12 ++++++++---- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index 81867bd..998bb66 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -97,6 +97,7 @@ "compose.attachment.cancel-upload.accessibility-label" = "Cancel uploading attachment"; "compose.attachment.edit" = "Edit attachment"; "compose.attachment.remove" = "Remove attachment"; +"compose.attachment.uncaptioned" = "Uncaptioned"; "compose.attachment.uploading" = "Uploading"; "compose.attachments-button.accessibility-label" = "Add attachment"; "compose.attachments-will-be-discarded" = "Attachments will be discarded when changing accounts"; diff --git a/Metatext.xcodeproj/project.pbxproj b/Metatext.xcodeproj/project.pbxproj index e89c92a..44ba9cc 100644 --- a/Metatext.xcodeproj/project.pbxproj +++ b/Metatext.xcodeproj/project.pbxproj @@ -141,6 +141,7 @@ D0B32F50250B373600311912 /* RegistrationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B32F4F250B373600311912 /* RegistrationView.swift */; }; D0B5FE9B251583DB00478838 /* ProfileCollection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B5FE9A251583DB00478838 /* ProfileCollection+Extensions.swift */; }; D0B8510C25259E56004E0744 /* LoadMoreTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B8510B25259E56004E0744 /* LoadMoreTableViewCell.swift */; }; + D0BE633125F2C409001139FA /* CapsuleLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F4525C72E50005C5368 /* CapsuleLabel.swift */; }; D0BE97A325CF44310057E161 /* CGRect+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BE97A225CF44310057E161 /* CGRect+Extensions.swift */; }; D0BE97D725D0863E0057E161 /* ImagePastableTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BE97D625D0863E0057E161 /* ImagePastableTextView.swift */; }; D0BE97E025D086F80057E161 /* ImagePastableTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BE97D625D0863E0057E161 /* ImagePastableTextView.swift */; }; @@ -1267,6 +1268,7 @@ D059373425AAEA7000754FDF /* CompositionPollView.swift in Sources */, D021A67B25C3E32A008A0C0D /* PlayerView.swift in Sources */, D052DBDD25EAF01800FFB628 /* URL+Extensions.swift in Sources */, + D0BE633125F2C409001139FA /* CapsuleLabel.swift in Sources */, D005A20125EF574F008B2E63 /* NavigationHandling.swift in Sources */, D021A69025C3E4B8008A0C0D /* EmojiContentConfiguration.swift in Sources */, D08E52D2257C811200FA2C5F /* ShareExtensionError+Extensions.swift in Sources */, diff --git a/Views/UIKit/AttachmentView.swift b/Views/UIKit/AttachmentView.swift index 8248dc4..2dafe3c 100644 --- a/Views/UIKit/AttachmentView.swift +++ b/Views/UIKit/AttachmentView.swift @@ -11,7 +11,7 @@ final class AttachmentView: UIView { let playerView = PlayerView() let imageView = SDAnimatedImageView() let removeButton = UIButton(type: .close) - let editIcon = UIImageView() + let uncaptionedLabel = CapsuleLabel() let selectionButton = UIButton() var playing: Bool = false { @@ -159,14 +159,11 @@ private extension AttachmentView { self.parentViewModel.removeAttachment(viewModel: self.viewModel) }]) - addSubview(editIcon) - editIcon.translatesAutoresizingMaskIntoConstraints = false - editIcon.image = UIImage( - systemName: "pencil", - withConfiguration: UIImage.SymbolConfiguration(scale: .large)) - editIcon.layer.shadowOffset = .zero - editIcon.layer.shadowRadius = .defaultShadowRadius - editIcon.layer.shadowOpacity = .defaultShadowOpacity + addSubview(uncaptionedLabel) + uncaptionedLabel.translatesAutoresizingMaskIntoConstraints = false + uncaptionedLabel.text = NSLocalizedString("compose.attachment.uncaptioned", comment: "") + uncaptionedLabel.isHidden = !(parentViewModel.canRemoveAttachments + && (viewModel.attachment.description?.isEmpty ?? true)) switch viewModel.attachment.type { case .image, .video, .gifv: @@ -224,8 +221,8 @@ private extension AttachmentView { selectionButton.bottomAnchor.constraint(equalTo: bottomAnchor), removeButton.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor), removeButton.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor), - editIcon.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor), - editIcon.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor) + uncaptionedLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor), + uncaptionedLabel.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor) ]) var accessibilityLabel = viewModel.attachment.type.accessibilityName diff --git a/Views/UIKit/AttachmentsView.swift b/Views/UIKit/AttachmentsView.swift index 3443883..515f346 100644 --- a/Views/UIKit/AttachmentsView.swift +++ b/Views/UIKit/AttachmentsView.swift @@ -33,7 +33,6 @@ final class AttachmentsView: UIView { let attachmentView = AttachmentView(viewModel: attachmentViewModel, parentViewModel: viewModel) attachmentView.playing = viewModel.shouldShowAttachments && attachmentViewModel.shouldAutoplay attachmentView.removeButton.isHidden = !viewModel.canRemoveAttachments - attachmentView.editIcon.isHidden = !viewModel.canRemoveAttachments attachmentView.isAccessibilityElement = !viewModel.canRemoveAttachments if viewModel.attachmentViewModels.count == 2 && index == 1 diff --git a/Views/UIKit/CapsuleLabel.swift b/Views/UIKit/CapsuleLabel.swift index c56e2e6..fd17b91 100644 --- a/Views/UIKit/CapsuleLabel.swift +++ b/Views/UIKit/CapsuleLabel.swift @@ -17,25 +17,29 @@ final class CapsuleLabel: UILabel { override func layoutSubviews() { super.layoutSubviews() - layer.cornerRadius = inset + layer.cornerRadius = bounds.height / 2 invalidateIntrinsicContentSize() } override func drawText(in rect: CGRect) { - super.drawText(in: rect.inset(by: .init(top: 0, left: inset, bottom: 0, right: inset))) + super.drawText(in: rect.inset(by: .init( + top: .compactSpacing, + left: .defaultSpacing, + bottom: .compactSpacing, + right: .defaultSpacing))) } override var intrinsicContentSize: CGSize { var size = super.intrinsicContentSize - size.width += inset * 2 + size.width += .defaultSpacing * 2 + size.height += .compactSpacing * 2 return size } } private extension CapsuleLabel { - var inset: CGFloat { bounds.height / 2 } func initialSetup() { backgroundColor = .secondarySystemBackground