Skip to content

Commit

Permalink
Apply the post language to the AltViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed Jan 12, 2023
1 parent 1ff8453 commit b76f9eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Mastodon/Scene/MediaPreview/AltViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ class AltViewController: UIViewController {

textView.textContainer.maximumNumberOfLines = 0
textView.textContainer.lineBreakMode = .byWordWrapping
textView.font = .preferredFont(forTextStyle: .callout)
textView.isScrollEnabled = true
textView.backgroundColor = .clear
textView.isOpaque = false
textView.isEditable = false
textView.tintColor = .white
textView.textContainerInset = UIEdgeInsets(top: 12, left: 8, bottom: 8, right: 8)
textView.contentInsetAdjustmentBehavior = .always
textView.verticalScrollIndicatorInsets.bottom = 4

return textView
}()

init(alt: String, sourceView: UIView?) {
textView.text = alt
init(alt: String, language: String?, sourceView: UIView?) {
textView.attributedText = NSAttributedString(string: alt, attributes: [
.languageIdentifier: "",
.foregroundColor: UIColor.white,
.font: UIFont.preferredFont(forTextStyle: .callout),
])
super.init(nibName: nil, bundle: nil)
self.modalPresentationStyle = .popover
self.popoverPresentationController?.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ extension MediaPreviewViewController {
@objc private func altButtonPressed(_ sender: UIButton) {
guard let alt = viewModel.altText else { return }

present(AltViewController(alt: alt, sourceView: sender), animated: true)
present(AltViewController(alt: alt, language: viewModel.language, sourceView: sender), animated: true)
}
}

Expand Down
2 changes: 2 additions & 0 deletions Mastodon/Scene/MediaPreview/MediaPreviewViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class MediaPreviewViewModel: NSObject {
@Published var currentPage: Int
@Published var showingChrome = true
@Published var altText: String?
@Published var language: String?

// output
let viewControllers: [MediaPreviewPage]
Expand All @@ -47,6 +48,7 @@ final class MediaPreviewViewModel: NSObject {
switch item {
case .attachment(let previewContext):
getAltText = { previewContext.attachments[$0].altDescription }
self.language = previewContext.language

currentPage = previewContext.initialIndex
for (i, attachment) in previewContext.attachments.enumerated() {
Expand Down

0 comments on commit b76f9eb

Please sign in to comment.