Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HomeLastPicCollectionViewCell): Cancel previous request when preparing for reuse #1094

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kDrive/UI/View/Home/HomeLastPicCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import kDriveCore
import kDriveResources
import Kingfisher
import UIKit

class HomeLastPicCollectionViewCell: UICollectionViewCell {
Expand All @@ -27,6 +28,8 @@ class HomeLastPicCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var checkmarkImage: UIImageView!
@IBOutlet weak var videoData: UIView!

private var thumbnailDownloadTask: Kingfisher.DownloadTask?

override var isSelected: Bool {
didSet {
configureForSelection()
Expand All @@ -52,6 +55,7 @@ class HomeLastPicCollectionViewCell: UICollectionViewCell {

override func prepareForReuse() {
super.prepareForReuse()
thumbnailDownloadTask?.cancel()
darkLayer.isHidden = true
fileImage.image = nil
fileImage.backgroundColor = nil
Expand All @@ -75,7 +79,7 @@ class HomeLastPicCollectionViewCell: UICollectionViewCell {
self.file = file
checkmarkImage.isHidden = !selectionMode
darkLayer.isHidden = false
file.getThumbnail { [weak self, fileId = file.id] image, isThumbnail in
thumbnailDownloadTask = file.getThumbnail { [weak self, fileId = file.id] image, isThumbnail in
if fileId == self?.file?.id {
self?.darkLayer.isHidden = true
self?.fileImage.image = isThumbnail ? image : KDriveResourcesAsset.fileImageSmall.image
Expand Down
Loading