diff --git a/Modules/Presentation/Features/Video/Sources/Video/Views/Videos/Cells/VideoCellTextView.swift b/Modules/Presentation/Features/Video/Sources/Video/Views/Videos/Cells/VideoCellTextView.swift index ec4e4dbdb8..2a617a73df 100644 --- a/Modules/Presentation/Features/Video/Sources/Video/Views/Videos/Cells/VideoCellTextView.swift +++ b/Modules/Presentation/Features/Video/Sources/Video/Views/Videos/Cells/VideoCellTextView.swift @@ -71,11 +71,12 @@ private struct VideoCellTitleTextRepresentable: UIViewRepresentable { textView.isScrollEnabled = false textView.isEditable = false textView.isSelectable = false - textView.textContainer.maximumNumberOfLines = 2 - textView.textContainer.lineBreakMode = .byTruncatingTail + updateMaximumNumberOfLines(for: textView) + textView.textContainer.lineBreakMode = .byTruncatingMiddle textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) textView.backgroundColor = backgroundColor removeContentInset(of: textView) + monitorSizeCategoryChanged(on: textView) return textView } @@ -84,6 +85,26 @@ private struct VideoCellTitleTextRepresentable: UIViewRepresentable { textView.textContainerInset = .zero } + private func monitorSizeCategoryChanged(on textView: UITextView) { + NotificationCenter.default.addObserver( + forName: UIContentSizeCategory.didChangeNotification, + object: nil, + queue: .main + ) { _ in + updateMaximumNumberOfLines(for: textView) + textView.attributedText = createAttributedTitle() + } + } + + private func updateMaximumNumberOfLines(for textView: UITextView) { + switch UIApplication.shared.preferredContentSizeCategory { + case .extraSmall, .small, .medium, .large: + textView.textContainer.maximumNumberOfLines = 2 + default: + textView.textContainer.maximumNumberOfLines = 1 + } + } + func updateUIView(_ textView: UITextView, context: Context) { textView.attributedText = createAttributedTitle() }