fix: image may block to fetch issue

This commit is contained in:
CMK 2021-07-07 16:10:39 +08:00
parent a90dac248a
commit e5e9f83a23
4 changed files with 15 additions and 9 deletions

View File

@ -675,9 +675,7 @@ extension StatusSection {
case .success:
statusItemAttribute.isImageLoaded.value = true
}
}?
.store(in: &cell.statusView.statusMosaicImageViewContainer.imageTasks)
}
imageView.accessibilityLabel = meta.altText

View File

@ -24,8 +24,6 @@ final class MosaicImageViewContainer: UIView {
weak var delegate: MosaicImageViewContainerDelegate?
var imageTasks = Set<ImageTask?>()
let container = UIStackView()
private(set) lazy var imageViews: [UIImageView] = {
(0..<4).map { _ -> UIImageView in
@ -95,9 +93,14 @@ 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)

View File

@ -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

View File

@ -13,6 +13,7 @@ import CoreDataStack
import MastodonSDK
import AlamofireImage
import AlamofireNetworkActivityIndicator
import Nuke
final class APIService {
@ -35,6 +36,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
NetworkActivityIndicatorManager.shared.startDelay = 0.2