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

Commit 367ea34

Browse files
committed
Temp fix for iPad theme changes bug, Fixed crashes with BAD_ACCESS on AsyncTextAttachment
1 parent 806b3b1 commit 367ea34

File tree

6 files changed

+22
-27
lines changed

6 files changed

+22
-27
lines changed

Slide for Reddit/AsyncTextAttachment.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,39 +70,42 @@ public class AsyncTextAttachment: NSTextAttachment {
7070
// MARK: - Helpers
7171

7272
private func startAsyncImageDownload() {
73-
guard let imageURL = imageURL, contents == nil else {
73+
guard let imageURL = imageURL else {
7474
return
7575
}
7676

7777
DispatchQueue.global(qos: .background).async {
78-
if let image = SDImageCache.shared.imageFromCache(forKey: imageURL.absoluteString) {
78+
if let image = self.getCacheImage(with: imageURL) {
7979
self.display(image, with: image.pngData(), url: imageURL)
8080
} else {
8181
self.downloadImage(with: imageURL)
8282
}
8383
}
8484
}
8585

86+
private func getCacheImage(with: URL) -> UIImage? {
87+
return SDImageCache.shared.imageFromCache(forKey: with.absoluteString)
88+
}
89+
8690
private func downloadImage(with: URL) {
8791
SDWebImageDownloader.shared.downloadImage(with: with, options: [.decodeFirstFrameOnly], progress: nil) { (image, data, _, _) in
88-
self.display(image, with: data, url: with)
92+
let roundedImage = image?.circleCorners(finalSize: self.bounds.size)
93+
DispatchQueue.global(qos: .background).async {
94+
SDImageCache.shared.storeImage(toMemory: roundedImage, forKey: with.absoluteString)
95+
}
96+
97+
self.display(roundedImage, with: data, url: with)
8998
}
9099
}
91100

92101
public func display(_ image: UIImage?, with: Data?, url: URL) {
93-
self.contents = with
94-
95-
DispatchQueue.global(qos: .background).async {
96-
SDImageCache.shared.storeImage(toMemory: image, forKey: url.absoluteString)
97-
}
98102
let ext = url.pathExtension as CFString
99103
if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext, nil) {
100104
self.fileType = uti.takeRetainedValue() as String
101105
}
102-
if let image = image?.circleCorners(finalSize: self.bounds.size) { //2 was causing weird clipping
106+
if let image = image { //2 was causing weird clipping
103107
let imageSize = image.size
104108

105-
self.contents = image.pngData()
106109
self.originalImageSize = imageSize
107110
}
108111

@@ -116,7 +119,7 @@ public class AsyncTextAttachment: NSTextAttachment {
116119
public override func image(forBounds imageBounds: CGRect, textContainer: NSTextContainer?, characterIndex charIndex: Int) -> UIImage? {
117120
if let image = image { return image }
118121

119-
guard let contents = contents, let image = UIImage(data: contents) else {
122+
guard let url = imageURL, let image = getCacheImage(with: url) else {
120123
// remember reference so that we can update it later
121124
self.textContainer = textContainer
122125

Slide for Reddit/CommentViewController.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,16 +1428,8 @@ class CommentViewController: MediaViewController, UITableViewDelegate, UITableVi
14281428

14291429
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
14301430
super.traitCollectionDidChange(previousTraitCollection)
1431-
if #available(iOS 13.0, *) {
1432-
if #available(iOS 14.0, *) {
1433-
if UIDevice.current.userInterfaceIdiom == .pad {
1434-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { //Wait for 0.1 seconds. There is a race condition here that sets the theme twice on iPad
1435-
if previousTraitCollection?.userInterfaceStyle != self.traitCollection.userInterfaceStyle {
1436-
ColorUtil.matchTraitCollection()
1437-
}
1438-
}
1439-
}
1440-
} else {
1431+
if UIDevice.current.userInterfaceIdiom == .phone { //TODO: iPad there is a bug here
1432+
if #available(iOS 13.0, *) {
14411433
if let themeChanged = previousTraitCollection?.hasDifferentColorAppearance(comparedTo: traitCollection) {
14421434
if themeChanged {
14431435
ColorUtil.matchTraitCollection()

Slide for Reddit/SettingsGeneral.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ class SettingsGeneral: BubbleSettingTableViewController {
497497
actionSheetController.show(self)
498498
}
499499

500-
501500
func showTimeMenu(s: LinkSortType, selector: UIView?) {
502501
if s == .hot || s == .new || s == .rising || s == .best {
503502
SettingValues.defaultSorting = s
@@ -530,8 +529,9 @@ class SettingsGeneral: BubbleSettingTableViewController {
530529
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
531530
tableView.deselectRow(at: indexPath, animated: true)
532531
self.timeMenuView = self.tableView.cellForRow(at: indexPath)!.contentView
533-
534-
if indexPath.section == 4 && indexPath.row == 0 {
532+
if indexPath.section == 0 && indexPath.row == 1 {
533+
changeFab()
534+
} else if indexPath.section == 4 && indexPath.row == 0 {
535535
showMenu(tableView.cellForRow(at: indexPath))
536536
} else if indexPath.section == 4 && indexPath.row == 1 {
537537
showMenuComments(tableView.cellForRow(at: indexPath))

Slide for Reddit/SettingsTheme.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class SettingsTheme: BubbleSettingTableViewController, ColorPickerViewDelegate {
125125
presenter.sourceRect = selectedTableView.bounds
126126
}
127127

128-
present(alertController, animated: true, completion: nil)
128+
present(alertController, animated: false, completion: nil)
129129
}
130130
}
131131

@@ -210,7 +210,6 @@ class SettingsTheme: BubbleSettingTableViewController, ColorPickerViewDelegate {
210210
}
211211

212212
present(alertController, animated: true, completion: nil)
213-
214213
}
215214
}
216215

Slide for Reddit/SingleSubredditViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ class SingleSubredditViewController: MediaViewController, AutoplayScrollViewDele
301301
isModal = navigationController?.presentingViewController != nil || self.modalPresentationStyle == .fullScreen
302302

303303
if isModal {
304-
self.navigationController?.delegate = self
305304
if self.navigationController is TapBehindModalViewController {
305+
self.navigationController?.delegate = self
306306
(self.navigationController as! TapBehindModalViewController).del = self
307307
}
308308
}

Slide for Reddit/SplitMainViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ extension SplitMainViewController: NavigationHomeDelegate {
10241024
}
10251025
case .POPOVER_AFTER_NAVIGATION:
10261026
if let nav = homeViewController.navigationController as? SwipeForwardNavigationController, nav.topViewController != self, nav.pushableViewControllers.count > 0 {
1027+
nav.delegate = nav //Fixes strange case where the nav delegate is either overwritten or not equal to self, which is needed for the toExecute() stuff
10271028
nav.pushNextViewControllerFromRight() {
10281029
if let present = toPresent {
10291030
VCPresenter.showVC(viewController: present, popupIfPossible: true, parentNavigationController: homeViewController.navigationController, parentViewController: homeViewController)

0 commit comments

Comments
 (0)