This commit is contained in:
Justin Mazzocchi 2021-01-03 13:55:04 -08:00
parent 4806c43202
commit bf7110f5e2
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
3 changed files with 31 additions and 11 deletions

View file

@ -39,7 +39,7 @@
"camera-access.open-system-settings" = "Open system settings"; "camera-access.open-system-settings" = "Open system settings";
"cancel" = "Cancel"; "cancel" = "Cancel";
"compose.attachment.uploading" = "Uploading"; "compose.attachment.uploading" = "Uploading";
"compose.attachment.remove" = "Remove"; "compose.prompt" = "What's on your mind?";
"error" = "Error"; "error" = "Error";
"favorites" = "Favorites"; "favorites" = "Favorites";
"registration.review-terms-of-use-and-privacy-policy-%@" = "Please review %@'s Terms of Use and Privacy Policy to continue"; "registration.review-terms-of-use-and-privacy-policy-%@" = "Please review %@'s Terms of Use and Privacy Policy to continue";
@ -135,6 +135,7 @@
"notifications.poll-ended" = "A poll you have voted in has ended"; "notifications.poll-ended" = "A poll you have voted in has ended";
"notifications.your-poll-ended" = "Your poll has ended"; "notifications.your-poll-ended" = "Your poll has ended";
"notifications.unknown" = "Notification from %@"; "notifications.unknown" = "Notification from %@";
"remove" = "Remove";
"report" = "Report"; "report" = "Report";
"report.hint" = "The report will be sent to your server moderators. You can provide an explanation of why you are reporting this account below:"; "report.hint" = "The report will be sent to your server moderators. You can provide an explanation of why you are reporting this account below:";
"report.placeholder" = "Additional comments"; "report.placeholder" = "Additional comments";

View file

@ -65,8 +65,8 @@ private extension CompositionAttachmentView {
removeButton.menu = UIMenu( removeButton.menu = UIMenu(
children: [ children: [
UIAction( UIAction(
title: NSLocalizedString("compose.attachment.remove", comment: ""), title: NSLocalizedString("remove", comment: ""),
image: UIImage(systemName: "xmark.circle.fill"), image: UIImage(systemName: "trash"),
attributes: .destructive, handler: { [weak self] _ in attributes: .destructive, handler: { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }

View file

@ -9,6 +9,7 @@ final class CompositionView: UIView {
let avatarImageView = UIImageView() let avatarImageView = UIImageView()
let spoilerTextField = UITextField() let spoilerTextField = UITextField()
let textView = UITextView() let textView = UITextView()
let textViewPlaceholder = UILabel()
let attachmentUploadView = AttachmentUploadView() let attachmentUploadView = AttachmentUploadView()
let attachmentsCollectionView: UICollectionView let attachmentsCollectionView: UICollectionView
@ -92,8 +93,7 @@ private extension CompositionView {
stackView.spacing = .defaultSpacing stackView.spacing = .defaultSpacing
stackView.addArrangedSubview(spoilerTextField) stackView.addArrangedSubview(spoilerTextField)
spoilerTextField.backgroundColor = .secondarySystemBackground spoilerTextField.borderStyle = .roundedRect
spoilerTextField.layer.cornerRadius = .defaultCornerRadius
spoilerTextField.adjustsFontForContentSizeCategory = true spoilerTextField.adjustsFontForContentSizeCategory = true
spoilerTextField.font = .preferredFont(forTextStyle: .body) spoilerTextField.font = .preferredFont(forTextStyle: .body)
spoilerTextField.placeholder = NSLocalizedString("status.spoiler-text-placeholder", comment: "") spoilerTextField.placeholder = NSLocalizedString("status.spoiler-text-placeholder", comment: "")
@ -106,17 +106,24 @@ private extension CompositionView {
}, },
for: .editingChanged) for: .editingChanged)
let textViewFont = UIFont.preferredFont(forTextStyle: .body)
stackView.addArrangedSubview(textView) stackView.addArrangedSubview(textView)
textView.backgroundColor = .secondarySystemBackground
textView.layer.cornerRadius = .defaultCornerRadius
textView.isScrollEnabled = false textView.isScrollEnabled = false
textView.adjustsFontForContentSizeCategory = true textView.adjustsFontForContentSizeCategory = true
textView.font = .preferredFont(forTextStyle: .body) textView.font = textViewFont
// textView.textContainer.lineFragmentPadding = 0 textView.textContainerInset = .zero
textView.textContainer.lineFragmentPadding = 0
textView.inputAccessoryView = inputAccessoryView textView.inputAccessoryView = inputAccessoryView
textView.inputAccessoryView?.sizeToFit() textView.inputAccessoryView?.sizeToFit()
textView.delegate = self textView.delegate = self
textView.setContentHuggingPriority(.required, for: .vertical)
textView.addSubview(textViewPlaceholder)
textViewPlaceholder.translatesAutoresizingMaskIntoConstraints = false
textViewPlaceholder.adjustsFontForContentSizeCategory = true
textViewPlaceholder.font = .preferredFont(forTextStyle: .body)
textViewPlaceholder.textColor = .secondaryLabel
textViewPlaceholder.text = NSLocalizedString("compose.prompt", comment: "")
stackView.addArrangedSubview(attachmentsCollectionView) stackView.addArrangedSubview(attachmentsCollectionView)
attachmentsCollectionView.dataSource = attachmentsDataSource attachmentsCollectionView.dataSource = attachmentsDataSource
@ -127,6 +134,14 @@ private extension CompositionView {
textView.text = viewModel.text textView.text = viewModel.text
spoilerTextField.text = viewModel.contentWarning spoilerTextField.text = viewModel.contentWarning
let textViewBaselineConstraint = textView.topAnchor.constraint(
lessThanOrEqualTo: avatarImageView.centerYAnchor,
constant: -textViewFont.lineHeight / 2)
viewModel.$text.map(\.isEmpty)
.sink { [weak self] in self?.textViewPlaceholder.isHidden = !$0 }
.store(in: &cancellables)
viewModel.$displayContentWarning viewModel.$displayContentWarning
.sink { [weak self] in .sink { [weak self] in
guard let self = self else { return } guard let self = self else { return }
@ -138,6 +153,7 @@ private extension CompositionView {
} }
self.spoilerTextField.isHidden = !$0 self.spoilerTextField.isHidden = !$0
textViewBaselineConstraint.isActive = !$0
} }
.store(in: &cancellables) .store(in: &cancellables)
@ -164,9 +180,12 @@ private extension CompositionView {
avatarImageView.leadingAnchor.constraint(equalTo: guide.leadingAnchor), avatarImageView.leadingAnchor.constraint(equalTo: guide.leadingAnchor),
avatarImageView.bottomAnchor.constraint(lessThanOrEqualTo: guide.bottomAnchor), avatarImageView.bottomAnchor.constraint(lessThanOrEqualTo: guide.bottomAnchor),
stackView.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: .defaultSpacing), stackView.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: .defaultSpacing),
stackView.topAnchor.constraint(equalTo: guide.topAnchor), stackView.topAnchor.constraint(greaterThanOrEqualTo: guide.topAnchor),
stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor), stackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor),
stackView.bottomAnchor.constraint(lessThanOrEqualTo: guide.bottomAnchor), stackView.bottomAnchor.constraint(lessThanOrEqualTo: guide.bottomAnchor),
textViewPlaceholder.leadingAnchor.constraint(equalTo: textView.leadingAnchor),
textViewPlaceholder.topAnchor.constraint(equalTo: textView.topAnchor),
textViewPlaceholder.trailingAnchor.constraint(equalTo: textView.trailingAnchor),
attachmentsCollectionView.heightAnchor.constraint(equalToConstant: Self.attachmentCollectionViewHeight) attachmentsCollectionView.heightAnchor.constraint(equalToConstant: Self.attachmentCollectionViewHeight)
] ]