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

Commit e4c614b

Browse files
committed
Remove YYText and totally break the app
1 parent cd173b3 commit e4c614b

File tree

5 files changed

+171
-90
lines changed

5 files changed

+171
-90
lines changed

Slide for Reddit.xcodeproj/project.pbxproj

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
09F48EBC20F652CF00BAC8AC /* VideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09F48EBB20F652CF00BAC8AC /* VideoView.swift */; };
4747
2D3972CE071AEB2AC2811512 /* Pods_Slide_for_RedditTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 733616027CB406046CABF77A /* Pods_Slide_for_RedditTests.framework */; };
4848
323EFB2821434781005157FA /* ProgressBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 323EFB2721434781005157FA /* ProgressBarView.swift */; };
49+
B4BF517224D4EA23000000D9 /* CoolTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4BF517124D4EA23000000D9 /* CoolTextView.swift */; };
4950
B776B17D5CA92860424F37C0 /* ModQueueContributionLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B776BA7C2B7217C3875F3BEC /* ModQueueContributionLoader.swift */; };
5051
B776B1DF80711B443ED76B61 /* SettingsPro.swift in Sources */ = {isa = PBXBuildFile; fileRef = B776B2AEE4A2438F5803329C /* SettingsPro.swift */; };
5152
B776B1E23F4DEC18069F1579 /* MediaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B776BC65995FE8D1EE75E2AB /* MediaViewController.swift */; };
@@ -455,6 +456,7 @@
455456
5A3C22D1F67B7A388DDF34E6 /* Pods-Slide for Reddit.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Slide for Reddit.release.xcconfig"; path = "Pods/Target Support Files/Pods-Slide for Reddit/Pods-Slide for Reddit.release.xcconfig"; sourceTree = "<group>"; };
456457
733616027CB406046CABF77A /* Pods_Slide_for_RedditTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Slide_for_RedditTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
457458
B12412FF705B2BEB9D3B245F /* Pods_Slide_for_Reddit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Slide_for_Reddit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
459+
B4BF517124D4EA23000000D9 /* CoolTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoolTextView.swift; sourceTree = "<group>"; };
458460
B776B21CFB79FA354C296037 /* ColorMuxPagingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorMuxPagingViewController.swift; sourceTree = "<group>"; };
459461
B776B2AEE4A2438F5803329C /* SettingsPro.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsPro.swift; sourceTree = "<group>"; };
460462
B776B2E54F7438959A76E42E /* LiveThreadUpdate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiveThreadUpdate.swift; sourceTree = "<group>"; };
@@ -1302,6 +1304,34 @@
13021304
BE15FE742163D03900288D86 /* TopLockViewController.swift */,
13031305
BECF52432012AF7A00A310F9 /* VCPresenter.swift */,
13041306
BE11351B2159390700502C5B /* WatchSessionManager.swift */,
1307+
BE17A24F215FFFAA002C6CE6 /* ReadLaterContributionLoader.swift */,
1308+
BE17A2512160127C002C6CE6 /* ReadLaterViewController.swift */,
1309+
BE15FE742163D03900288D86 /* TopLockViewController.swift */,
1310+
BE8264E82194AE0E002A540E /* OfflineOverviewViewController.swift */,
1311+
BE25402521CCC03E003BD547 /* ForceTouchGestureRecognizer.swift */,
1312+
BE8AE94221F9225000E1C0D1 /* Main.storyboard */,
1313+
BE8AE94621F922F400E1C0D1 /* ColorPickerViewController.swift */,
1314+
BE47AF70225C574700A61FB0 /* ManageMultireddit.swift */,
1315+
BE762C9422A2FF7200B29757 /* DraftFindReturnViewController.swift */,
1316+
BE602AF9229F3A5200AF0DC3 /* LinkBubble.swift */,
1317+
BE7A2D3D22AD99600005F74F /* DragDownAlertMenu.swift */,
1318+
BEC4A1A3232E98CF00EE5114 /* ProfileInfoViewController.swift */,
1319+
BEC4A1B1232F3B4F00EE5114 /* collections.plist */,
1320+
BEC4A1B3232F3F1800EE5114 /* CollectionsContributionLoader.swift */,
1321+
BEC4A1B5232F3F9A00EE5114 /* CollectionsViewController.swift */,
1322+
BEC4A1B72331533400EE5114 /* AutoplayScrollViewHandler.swift */,
1323+
BEB7BAD923A05F2500E39593 /* InsetTransitioningDelegate.swift */,
1324+
BEC814EB24BD43EE005C8E8C /* SiriShortcuts.swift */,
1325+
BEC814ED24BE8B94005C8E8C /* HistoryViewController.swift */,
1326+
BEC814EF24BE8BBD005C8E8C /* HistoryContributionLoader.swift */,
1327+
BE25CAD324C3A28300736CA5 /* SwipeForwardNavigationController.swift */,
1328+
BE25CAD524C3A65400736CA5 /* SwipeForwardAnimatedTransitioning.swift */,
1329+
BE25CAD924C4B02700736CA5 /* NavigationHomeViewController.swift */,
1330+
BE25CADB24C4E3DA00736CA5 /* MainViewController.swift */,
1331+
BE25CADD24C4E3FB00736CA5 /* SplitMainViewController.swift */,
1332+
BE93DECE24CE4D8300464B64 /* icons.plist */,
1333+
BE93DED024CE550800464B64 /* subcolors.plist */,
1334+
B4BF517124D4EA23000000D9 /* CoolTextView.swift */,
13051335
);
13061336
path = "Slide for Reddit";
13071337
sourceTree = "<group>";
@@ -2154,6 +2184,7 @@
21542184
09526EF8214C399F005A3F6B /* UIPanGestureRecognizer+Utilities.swift in Sources */,
21552185
B776B69E386227A51C8E10DF /* MediaTableViewController.swift in Sources */,
21562186
B776B1E23F4DEC18069F1579 /* MediaViewController.swift in Sources */,
2187+
B4BF517224D4EA23000000D9 /* CoolTextView.swift in Sources */,
21572188
);
21582189
runOnlyForDeploymentPostprocessing = 0;
21592190
};

Slide for Reddit/CommentDepthCell.swift

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class CommentDepthCell: MarginedTableViewCell, UIViewControllerPreviewingDelegat
148148
$0.isUserInteractionEnabled = true
149149
$0.accessibilityIdentifier = "Comment body"
150150
$0.ignoreHeight = true
151-
$0.firstTextView.textContainerInset = UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0)
151+
// TODOjon:
152+
// $0.firstTextView.textContainerInset = UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0)
152153
})
153154

154155
self.title = YYLabel().then({
@@ -2342,8 +2343,8 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
23422343
} else if self.commentBody.overflow.frame.contains(location) {
23432344
let innerLocation = self.commentBody.convert(location, to: self.commentBody.overflow)
23442345
for view in self.commentBody.overflow.subviews {
2345-
if view.frame.contains(innerLocation) && view is YYLabel {
2346-
return UITargetedPreview(view: self.commentBody, parameters: self.getLocationForPreviewedText(view as! YYLabel, innerLocation, self.previewedURL?.absoluteString, self.commentBody) ?? parameters)
2346+
if let view = view as? UILabel, view.frame.contains(innerLocation) {
2347+
return UITargetedPreview(view: self.commentBody, parameters: self.getLocationForPreviewedText(view, innerLocation, self.previewedURL?.absoluteString, self.commentBody) ?? parameters)
23472348
}
23482349
}
23492350
}
@@ -2362,8 +2363,8 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
23622363
} else if self.commentBody.overflow.frame.contains(location) {
23632364
let innerLocation = self.commentBody.convert(location, to: self.commentBody.overflow)
23642365
for view in self.commentBody.overflow.subviews {
2365-
if view.frame.contains(innerLocation) && view is YYLabel {
2366-
return getConfigurationForTextView(view as! YYLabel, innerLocation)
2366+
if let view = view as? UILabel, view.frame.contains(innerLocation) {
2367+
return getConfigurationForTextView(view, innerLocation)
23672368
}
23682369
}
23692370
} else if self.commentBody.links.frame.contains(location) {
@@ -2380,44 +2381,34 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
23802381
self.previewedVC = nil
23812382
}
23822383

2383-
func getLocationForPreviewedText(_ label: YYLabel, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
2384+
func getLocationForPreviewedText(_ textView: CoolTextView, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
23842385
if inputURL == nil {
23852386
return nil
23862387
}
2387-
let point = label.superview?.convert(location, to: label) ?? location
2388+
// TODOjon:
2389+
let point = textView.superview?.convert(location, to: textView) ?? location // Convert touch point from frame space to label space
23882390
var params: UIPreviewParameters?
2389-
if let attributedText = label.attributedText, let layoutManager = YYTextLayout(containerSize: label.frame.size, text: attributedText) {
2390-
let locationFinal = layoutManager.textPosition(for: point, lineIndex: layoutManager.lineIndex(for: point))
2391-
if locationFinal < 1000000 {
2392-
attributedText.enumerateAttribute(
2393-
.link,
2394-
in: NSRange(location: 0, length: attributedText.length)
2395-
) { (value, range, _) in
2396-
if let url = value as? NSURL {
2397-
if url.absoluteString == inputURL! {
2398-
let baseRects = layoutManager.selectionRects(for: YYTextRange(range: range))
2399-
var cgs = [NSValue]()
2400-
for rect in baseRects {
2401-
if changeRectTo != nil {
2402-
cgs.append(NSValue(cgRect: changeRectTo!.convert(rect.rect, from: label)))
2403-
} else {
2404-
cgs.append(NSValue(cgRect: rect.rect))
2405-
}
2406-
}
2407-
params = UIPreviewParameters(textLineRects: cgs)
2408-
params?.backgroundColor = .clear
2409-
}
2391+
if let attributedText = textView.attributedText {
2392+
attributedText.enumerateAttribute(
2393+
.link,
2394+
in: NSRange(location: 0, length: attributedText.length)
2395+
) { (value, range, _) in
2396+
if let url = value as? NSURL {
2397+
if url.absoluteString == inputURL! {
2398+
let rects = textView.selectionRects(for: range.toTextRange(textInput: textView)!).map {NSValue(cgRect: $0.rect)}
2399+
params = UIPreviewParameters(textLineRects: rects)
2400+
params?.backgroundColor = .clear
24102401
}
24112402
}
24122403
}
24132404
}
24142405
return params
24152406
}
24162407

2417-
func getConfigurationForTextView(_ label: YYLabel, _ location: CGPoint) -> UIContextMenuConfiguration? {
2418-
let point = label.superview?.convert(location, to: label) ?? location
2408+
func getConfigurationForTextView(_ textView: CoolTextView, _ location: CGPoint) -> UIContextMenuConfiguration? {
2409+
// let point = textView.superview?.convert(location, to: label) ?? location
24192410

2420-
if let attributedText = label.attributedText, let layoutManager = YYTextLayout(containerSize: label.frame.size, text: attributedText) {
2411+
if let attributedText = textView.attributedText, let layoutManager = YYTextLayout(containerSize: textView.frame.size, text: attributedText) {
24212412
let locationFinal = layoutManager.textPosition(for: point, lineIndex: layoutManager.lineIndex(for: point))
24222413
if locationFinal < 1000000 {
24232414
let attributes = attributedText.attributes(at: Int(locationFinal), effectiveRange: nil)
@@ -2547,3 +2538,37 @@ extension CommentDepthCell: UIContextMenuInteractionDelegate {
25472538
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: nil)
25482539
}
25492540
}
2541+
2542+
extension UILabel {
2543+
func boundingRect(forCharacterRange range: NSRange) -> CGRect? {
2544+
2545+
guard let attributedText = attributedText else { return nil }
2546+
2547+
let textStorage = NSTextStorage(attributedString: attributedText)
2548+
let layoutManager = NSLayoutManager()
2549+
2550+
textStorage.addLayoutManager(layoutManager)
2551+
2552+
let textContainer = NSTextContainer(size: bounds.size)
2553+
textContainer.lineFragmentPadding = 0.0
2554+
2555+
layoutManager.addTextContainer(textContainer)
2556+
2557+
var glyphRange = NSRange()
2558+
2559+
// Convert the range for glyphs.
2560+
layoutManager.characterRange(forGlyphRange: range, actualGlyphRange: &glyphRange)
2561+
2562+
return layoutManager.boundingRect(forGlyphRange: glyphRange, in: textContainer)
2563+
}
2564+
}
2565+
2566+
extension NSRange {
2567+
func toTextRange(textInput: UITextInput) -> UITextRange? {
2568+
if let rangeStart = textInput.position(from: textInput.beginningOfDocument, offset: location),
2569+
let rangeEnd = textInput.position(from: rangeStart, offset: length) {
2570+
return textInput.textRange(from: rangeStart, to: rangeEnd)
2571+
}
2572+
return nil
2573+
}
2574+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// CoolTextView.swift
3+
// Slide for Reddit
4+
//
5+
// Created by Jonathan Cole on 7/31/20.
6+
// Copyright © 2020 Haptic Apps. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class CoolTextView: UITextView {
12+
13+
/*
14+
// Only override draw() if you perform custom drawing.
15+
// An empty implementation adversely affects performance during animation.
16+
override func draw(_ rect: CGRect) {
17+
// Drawing code
18+
}
19+
*/
20+
21+
}

Slide for Reddit/LinkCellView.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,8 +3186,8 @@ 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 view.frame.contains(innerLocation) && view is YYLabel {
3190-
return UITargetedPreview(view: self.textView, parameters: self.getLocationForPreviewedText(view as! YYLabel, innerLocation, self.previewedURL?.absoluteString, self.textView) ?? parameters)
3189+
if let view = view as? UILabel, view.frame.contains(innerLocation) {
3190+
return UITargetedPreview(view: self.textView, parameters: self.getLocationForPreviewedText(view, innerLocation, self.previewedURL?.absoluteString, self.textView) ?? parameters)
31913191
}
31923192
}
31933193
}
@@ -3203,7 +3203,8 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
32033203
}
32043204
}
32053205

3206-
func getLocationForPreviewedText(_ label: YYLabel, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
3206+
func getLocationForPreviewedText(_ label: UILabel, _ location: CGPoint, _ inputURL: String?, _ changeRectTo: UIView? = nil) -> UIPreviewParameters? {
3207+
// TODOjon:
32073208
if inputURL == nil {
32083209
return nil
32093210
}
@@ -3247,8 +3248,8 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
32473248
let innerLocation = self.contentView.convert(innerPoint, to: self.textView.overflow)
32483249
print(innerLocation)
32493250
for view in self.textView.overflow.subviews {
3250-
if view.frame.contains(innerLocation) && view is YYLabel {
3251-
return getConfigurationForTextView(view as! YYLabel, innerLocation)
3251+
if let view = view as? UILabel, view.frame.contains(innerLocation) {
3252+
return getConfigurationForTextView(view, innerLocation)
32523253
}
32533254
}
32543255
}
@@ -3268,7 +3269,8 @@ extension LinkCellView: UIContextMenuInteractionDelegate {
32683269
return nil
32693270
}
32703271

3271-
func getConfigurationForTextView(_ label: YYLabel, _ location: CGPoint) -> UIContextMenuConfiguration? {
3272+
func getConfigurationForTextView(_ label: UILabel, _ location: CGPoint) -> UIContextMenuConfiguration? {
3273+
// TODOjon:
32723274
let point = label.superview?.convert(location, to: label) ?? location
32733275
if let attributedText = label.attributedText, let layoutManager = YYTextLayout(containerSize: label.frame.size, text: attributedText) {
32743276
let locationFinal = layoutManager.textPosition(for: point, lineIndex: layoutManager.lineIndex(for: point))

0 commit comments

Comments
 (0)