diff --git a/Mastodon/Diffiable/Section/StatusSection.swift b/Mastodon/Diffiable/Section/StatusSection.swift index 515c72a0e..33765424f 100644 --- a/Mastodon/Diffiable/Section/StatusSection.swift +++ b/Mastodon/Diffiable/Section/StatusSection.swift @@ -675,9 +675,7 @@ extension StatusSection { case .success: statusItemAttribute.isImageLoaded.value = true } - }? - .store(in: &cell.statusView.statusMosaicImageViewContainer.imageTasks) - + } imageView.accessibilityLabel = meta.altText diff --git a/Mastodon/Scene/Share/View/Container/MosaicImageViewContainer.swift b/Mastodon/Scene/Share/View/Container/MosaicImageViewContainer.swift index d60d40fe7..62f61a387 100644 --- a/Mastodon/Scene/Share/View/Container/MosaicImageViewContainer.swift +++ b/Mastodon/Scene/Share/View/Container/MosaicImageViewContainer.swift @@ -24,8 +24,6 @@ final class MosaicImageViewContainer: UIView { weak var delegate: MosaicImageViewContainerDelegate? - var imageTasks = Set() - let container = UIStackView() private(set) lazy var imageViews: [UIImageView] = { (0..<4).map { _ -> UIImageView in @@ -94,11 +92,16 @@ extension MosaicImageViewContainer { } extension MosaicImageViewContainer { + + func resetImageTask() { + imageViews.forEach { imageView in + Nuke.cancelRequest(for: imageView) + } + } func reset() { - imageTasks.forEach { $0?.cancel() } - imageTasks.removeAll() - + resetImageTask() + container.arrangedSubviews.forEach { subview in container.removeArrangedSubview(subview) subview.removeFromSuperview() diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift index 27461cfc6..0b3d3fddb 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift @@ -74,7 +74,7 @@ final class StatusTableViewCell: UITableViewCell, StatusCell { override func prepareForReuse() { super.prepareForReuse() selectionStyle = .default - statusView.statusMosaicImageViewContainer.reset() + statusView.statusMosaicImageViewContainer.resetImageTask() statusView.contentMetaText.textView.isSelectable = false statusView.updateContentWarningDisplay(isHidden: true, animated: false) statusView.statusMosaicImageViewContainer.contentWarningOverlayView.isUserInteractionEnabled = true diff --git a/Mastodon/Service/APIService/APIService.swift b/Mastodon/Service/APIService/APIService.swift index b38e2e059..1316f2cf0 100644 --- a/Mastodon/Service/APIService/APIService.swift +++ b/Mastodon/Service/APIService/APIService.swift @@ -13,6 +13,7 @@ import CoreDataStack import MastodonSDK import AlamofireImage import AlamofireNetworkActivityIndicator +import Nuke final class APIService { @@ -34,6 +35,10 @@ final class APIService { // setup cache. 10MB RAM + 50MB Disk URLCache.shared = URLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 50 * 1024 * 1024, diskPath: nil) + + // setup Nuke cache + // using LRU disk cache + ImagePipeline.shared = ImagePipeline(configuration: .withDataCache) // enable network activity manager for AlamofireImage NetworkActivityIndicatorManager.shared.isEnabled = true