Skip to content

Commit

Permalink
T17120577 - CC-6663 - Fix - The size of the videos titles is big with…
Browse files Browse the repository at this point in the history
… small iOS text size but small with big iOS text size opposite than expected
  • Loading branch information
af-mega committed Sep 4, 2024
1 parent 66c6997 commit 41cc4a0
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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()
}
Expand Down

0 comments on commit 41cc4a0

Please sign in to comment.