Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 854edb9

Browse files
committed
Initial UILabel cleanup
1 parent 3f199ed commit 854edb9

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

Slide for Reddit/CommentDepthCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
23432343
} else if self.commentBody.overflow.frame.contains(location) {
23442344
let innerLocation = self.commentBody.convert(location, to: self.commentBody.overflow)
23452345
for view in self.commentBody.overflow.subviews {
2346-
if let view = view as? UILabel, view.frame.contains(innerLocation) {
2346+
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
23472347
return UITargetedPreview(view: self.commentBody, parameters: self.getLocationForPreviewedText(view, innerLocation, self.previewedURL?.absoluteString, self.commentBody) ?? parameters)
23482348
}
23492349
}
@@ -2363,7 +2363,7 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
23632363
} else if self.commentBody.overflow.frame.contains(location) {
23642364
let innerLocation = self.commentBody.convert(location, to: self.commentBody.overflow)
23652365
for view in self.commentBody.overflow.subviews {
2366-
if let view = view as? UILabel, view.frame.contains(innerLocation) {
2366+
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
23672367
return getConfigurationForTextView(view, innerLocation)
23682368
}
23692369
}

Slide for Reddit/LinkCellView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
31863186
} else if self.textView.overflow.frame.contains(location) {
31873187
let innerLocation = self.textView.convert(location, to: self.textView.overflow)
31883188
for view in self.textView.overflow.subviews {
3189-
if let view = view as? UILabel, view.frame.contains(innerLocation) {
3189+
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
31903190
return UITargetedPreview(view: self.textView, parameters: self.getLocationForPreviewedText(view, innerLocation, self.previewedURL?.absoluteString, self.textView) ?? parameters)
31913191
}
31923192
}
@@ -3203,7 +3203,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
32033203
}
32043204
}
32053205

3206-
func getLocationForPreviewedText(_ label: UILabel, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
3206+
func getLocationForPreviewedText(_ label: CoolTextView, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
32073207
// TODOjon:
32083208
if inputURL == nil {
32093209
return nil
@@ -3248,7 +3248,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
32483248
let innerLocation = self.contentView.convert(innerPoint, to: self.textView.overflow)
32493249
print(innerLocation)
32503250
for view in self.textView.overflow.subviews {
3251-
if let view = view as? UILabel, view.frame.contains(innerLocation) {
3251+
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
32523252
return getConfigurationForTextView(view, innerLocation)
32533253
}
32543254
}
@@ -3269,7 +3269,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
32693269
return nil
32703270
}
32713271

3272-
func getConfigurationForTextView(_ label: UILabel, _ location: CGPoint) -> UIContextMenuConfiguration? {
3272+
func getConfigurationForTextView(_ label: CoolTextView, _ location: CGPoint) -> UIContextMenuConfiguration? {
32733273
// TODOjon:
32743274
let point = label.superview?.convert(location, to: label) ?? location
32753275
if let attributedText = label.attributedText, let layoutManager = YYTextLayout(containerSize: label.frame.size, text: attributedText) {

Slide for Reddit/TextDisplayStackView.swift

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class TextDisplayStackView: UIStackView {
3030
var estimatedHeight = CGFloat(0)
3131
weak var parentLongPress: UILongPressGestureRecognizer?
3232

33-
let firstTextView: UILabel
33+
let firstTextView: CoolTextView
3434
let overflow: UIStackView
3535
let links: UIScrollView
3636

@@ -54,7 +54,7 @@ public class TextDisplayStackView: UIStackView {
5454
self.tColor = .black
5555
self.baseFontColor = .white
5656
self.delegate = delegate
57-
self.firstTextView = UILabel(frame: .zero)
57+
self.firstTextView = CoolTextView(frame: .zero)
5858
self.overflow = UIStackView()
5959
self.overflow.isUserInteractionEnabled = true
6060
self.links = TouchUIScrollView()
@@ -114,9 +114,8 @@ public class TextDisplayStackView: UIStackView {
114114
self.tColor = color
115115
self.delegate = delegate
116116
self.baseFontColor = baseFontColor
117-
self.firstTextView = UILabel(frame: CGRect.zero).then({
117+
self.firstTextView = CoolTextView(frame: CGRect.zero).then({
118118
$0.accessibilityIdentifier = "Top title"
119-
$0.numberOfLines = 0
120119
$0.setContentCompressionResistancePriority(UILayoutPriority.required, for: .vertical)
121120
})
122121
self.links = TouchUIScrollView()
@@ -189,7 +188,6 @@ public class TextDisplayStackView: UIStackView {
189188
}
190189

191190
firstTextView.attributedText = string
192-
firstTextView.preferredMaxLayoutWidth = estimatedWidth
193191

194192
if !ignoreHeight {
195193
// let framesetterB = CTFramesetterCreateWithAttributedString(string)
@@ -256,7 +254,6 @@ public class TextDisplayStackView: UIStackView {
256254
}
257255

258256
firstTextView.attributedText = newTitle
259-
firstTextView.preferredMaxLayoutWidth = estimatedWidth
260257

261258
if !ignoreHeight {
262259
// let framesetterB = CTFramesetterCreateWithAttributedString(newTitle)
@@ -312,7 +309,6 @@ public class TextDisplayStackView: UIStackView {
312309
// firstTextView.linkAttributes = activeLinkAttributes as NSDictionary as? [AnyHashable: Any]
313310

314311
firstTextView.attributedText = newTitle
315-
firstTextView.preferredMaxLayoutWidth = estimatedWidth
316312

317313
if !ignoreHeight {
318314
// let framesetterB = CTFramesetterCreateWithAttributedString(newTitle)
@@ -423,7 +419,6 @@ public class TextDisplayStackView: UIStackView {
423419
}
424420

425421
firstTextView.attributedText = text
426-
firstTextView.preferredMaxLayoutWidth = estimatedWidth
427422

428423
if !ignoreHeight {
429424
// let framesetterB = CTFramesetterCreateWithAttributedString(text)
@@ -493,12 +488,10 @@ public class TextDisplayStackView: UIStackView {
493488
if body.isEmpty {
494489
continue
495490
}
496-
let label = UILabel(frame: .zero)
491+
let label = CoolTextView(frame: .zero)
497492
label.accessibilityIdentifier = "Quote"
498493
let text = createAttributedChunk(baseHTML: body, accent: tColor, linksCallback: linksCallback, indexCallback: indexCallback)
499494
label.alpha = 0.7
500-
label.numberOfLines = 0
501-
label.lineBreakMode = .byWordWrapping
502495
// TODOjon:
503496
// label.highlightLongPressAction = longTouchLinkAction
504497
// label.highlightTapAction = touchLinkAction
@@ -509,7 +502,6 @@ public class TextDisplayStackView: UIStackView {
509502

510503
let size = text.boundingSize(givenSize: CGSize(width: estimatedWidth - 12, height: CGFloat.greatestFiniteMagnitude))
511504
estimatedHeight += size.height
512-
label.preferredMaxLayoutWidth = size.width
513505
label.attributedText = text
514506

515507
baseView.addSubview(label)
@@ -529,10 +521,8 @@ public class TextDisplayStackView: UIStackView {
529521
continue
530522
}
531523
let text = createAttributedChunk(baseHTML: block.trimmed(), accent: tColor, linksCallback: linksCallback, indexCallback: indexCallback)
532-
let label = UILabel(frame: CGRect.zero).then {
524+
let label = CoolTextView(frame: CGRect.zero).then {
533525
$0.accessibilityIdentifier = "Paragraph"
534-
$0.numberOfLines = 0
535-
$0.lineBreakMode = .byWordWrapping
536526
$0.attributedText = text
537527
$0.setContentCompressionResistancePriority(UILayoutPriority.required, for: .vertical)
538528
}
@@ -541,7 +531,6 @@ public class TextDisplayStackView: UIStackView {
541531
// label.highlightTapAction = touchLinkAction
542532

543533
let size = text.boundingSize(givenSize: CGSize(width: estimatedWidth, height: CGFloat.greatestFiniteMagnitude))
544-
label.preferredMaxLayoutWidth = size.width
545534

546535
estimatedHeight += size.height
547536

0 commit comments

Comments
 (0)