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

Commit

Permalink
Initial UILabel cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrama committed Aug 11, 2020
1 parent 3f199ed commit 854edb9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Slide for Reddit/CommentDepthCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
} else if self.commentBody.overflow.frame.contains(location) {
let innerLocation = self.commentBody.convert(location, to: self.commentBody.overflow)
for view in self.commentBody.overflow.subviews {
if let view = view as? UILabel, view.frame.contains(innerLocation) {
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
return UITargetedPreview(view: self.commentBody, parameters: self.getLocationForPreviewedText(view, innerLocation, self.previewedURL?.absoluteString, self.commentBody) ?? parameters)
}
}
Expand All @@ -2363,7 +2363,7 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
} else if self.commentBody.overflow.frame.contains(location) {
let innerLocation = self.commentBody.convert(location, to: self.commentBody.overflow)
for view in self.commentBody.overflow.subviews {
if let view = view as? UILabel, view.frame.contains(innerLocation) {
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
return getConfigurationForTextView(view, innerLocation)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Slide for Reddit/LinkCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3186,7 +3186,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
} else if self.textView.overflow.frame.contains(location) {
let innerLocation = self.textView.convert(location, to: self.textView.overflow)
for view in self.textView.overflow.subviews {
if let view = view as? UILabel, view.frame.contains(innerLocation) {
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
return UITargetedPreview(view: self.textView, parameters: self.getLocationForPreviewedText(view, innerLocation, self.previewedURL?.absoluteString, self.textView) ?? parameters)
}
}
Expand All @@ -3203,7 +3203,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
}
}

func getLocationForPreviewedText(_ label: UILabel, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
func getLocationForPreviewedText(_ label: CoolTextView, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
// TODOjon:
if inputURL == nil {
return nil
Expand Down Expand Up @@ -3248,7 +3248,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
let innerLocation = self.contentView.convert(innerPoint, to: self.textView.overflow)
print(innerLocation)
for view in self.textView.overflow.subviews {
if let view = view as? UILabel, view.frame.contains(innerLocation) {
if let view = view as? CoolTextView, view.frame.contains(innerLocation) {
return getConfigurationForTextView(view, innerLocation)
}
}
Expand All @@ -3269,7 +3269,7 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
return nil
}

func getConfigurationForTextView(_ label: UILabel, _ location: CGPoint) -> UIContextMenuConfiguration? {
func getConfigurationForTextView(_ label: CoolTextView, _ location: CGPoint) -> UIContextMenuConfiguration? {
// TODOjon:
let point = label.superview?.convert(location, to: label) ?? location
if let attributedText = label.attributedText, let layoutManager = YYTextLayout(containerSize: label.frame.size, text: attributedText) {
Expand Down
21 changes: 5 additions & 16 deletions Slide for Reddit/TextDisplayStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TextDisplayStackView: UIStackView {
var estimatedHeight = CGFloat(0)
weak var parentLongPress: UILongPressGestureRecognizer?

let firstTextView: UILabel
let firstTextView: CoolTextView
let overflow: UIStackView
let links: UIScrollView

Expand All @@ -54,7 +54,7 @@ public class TextDisplayStackView: UIStackView {
self.tColor = .black
self.baseFontColor = .white
self.delegate = delegate
self.firstTextView = UILabel(frame: .zero)
self.firstTextView = CoolTextView(frame: .zero)
self.overflow = UIStackView()
self.overflow.isUserInteractionEnabled = true
self.links = TouchUIScrollView()
Expand Down Expand Up @@ -114,9 +114,8 @@ public class TextDisplayStackView: UIStackView {
self.tColor = color
self.delegate = delegate
self.baseFontColor = baseFontColor
self.firstTextView = UILabel(frame: CGRect.zero).then({
self.firstTextView = CoolTextView(frame: CGRect.zero).then({
$0.accessibilityIdentifier = "Top title"
$0.numberOfLines = 0
$0.setContentCompressionResistancePriority(UILayoutPriority.required, for: .vertical)
})
self.links = TouchUIScrollView()
Expand Down Expand Up @@ -189,7 +188,6 @@ public class TextDisplayStackView: UIStackView {
}

firstTextView.attributedText = string
firstTextView.preferredMaxLayoutWidth = estimatedWidth

if !ignoreHeight {
// let framesetterB = CTFramesetterCreateWithAttributedString(string)
Expand Down Expand Up @@ -256,7 +254,6 @@ public class TextDisplayStackView: UIStackView {
}

firstTextView.attributedText = newTitle
firstTextView.preferredMaxLayoutWidth = estimatedWidth

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

firstTextView.attributedText = newTitle
firstTextView.preferredMaxLayoutWidth = estimatedWidth

if !ignoreHeight {
// let framesetterB = CTFramesetterCreateWithAttributedString(newTitle)
Expand Down Expand Up @@ -423,7 +419,6 @@ public class TextDisplayStackView: UIStackView {
}

firstTextView.attributedText = text
firstTextView.preferredMaxLayoutWidth = estimatedWidth

if !ignoreHeight {
// let framesetterB = CTFramesetterCreateWithAttributedString(text)
Expand Down Expand Up @@ -493,12 +488,10 @@ public class TextDisplayStackView: UIStackView {
if body.isEmpty {
continue
}
let label = UILabel(frame: .zero)
let label = CoolTextView(frame: .zero)
label.accessibilityIdentifier = "Quote"
let text = createAttributedChunk(baseHTML: body, accent: tColor, linksCallback: linksCallback, indexCallback: indexCallback)
label.alpha = 0.7
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
// TODOjon:
// label.highlightLongPressAction = longTouchLinkAction
// label.highlightTapAction = touchLinkAction
Expand All @@ -509,7 +502,6 @@ public class TextDisplayStackView: UIStackView {

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

baseView.addSubview(label)
Expand All @@ -529,10 +521,8 @@ public class TextDisplayStackView: UIStackView {
continue
}
let text = createAttributedChunk(baseHTML: block.trimmed(), accent: tColor, linksCallback: linksCallback, indexCallback: indexCallback)
let label = UILabel(frame: CGRect.zero).then {
let label = CoolTextView(frame: CGRect.zero).then {
$0.accessibilityIdentifier = "Paragraph"
$0.numberOfLines = 0
$0.lineBreakMode = .byWordWrapping
$0.attributedText = text
$0.setContentCompressionResistancePriority(UILayoutPriority.required, for: .vertical)
}
Expand All @@ -541,7 +531,6 @@ public class TextDisplayStackView: UIStackView {
// label.highlightTapAction = touchLinkAction

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

estimatedHeight += size.height

Expand Down

0 comments on commit 854edb9

Please sign in to comment.