From cde6a33bedb87c91ba66a911dc165fbbe7039bc1 Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Mon, 29 Jan 2024 11:38:51 +0000 Subject: [PATCH] - fix heavy animated image loading --- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../Detail/CollectibleDetailImageCell.swift | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 8e6aeb1a..20a35227 100644 --- a/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -69,7 +69,7 @@ "location" : "https://github.com/kukai-wallet/kukai-core-swift", "state" : { "branch" : "develop", - "revision" : "102e4e263710946b67e3fc403125b7d2f585a179" + "revision" : "b6df6e2744c40ce32760c454f32b391bf84d86af" } }, { diff --git a/Kukai Mobile/Modules/Collectibles/Cells/Detail/CollectibleDetailImageCell.swift b/Kukai Mobile/Modules/Collectibles/Cells/Detail/CollectibleDetailImageCell.swift index 40bcb0fd..a102b684 100644 --- a/Kukai Mobile/Modules/Collectibles/Cells/Detail/CollectibleDetailImageCell.swift +++ b/Kukai Mobile/Modules/Collectibles/Cells/Detail/CollectibleDetailImageCell.swift @@ -18,16 +18,6 @@ class CollectibleDetailImageCell: UICollectionViewCell { public var setup = false func setup(mediaContent: MediaContent, layoutOnly: Bool) { - activityIndicator.isHidden = true - - - /* - if mediaContent.isThumbnail { - activityIndicator.startAnimating() - } else { - activityIndicator.isHidden = true - } - */ // If landscape image, remove the existing square image constraint and repalce with smaller height aspect ratio image if mediaContent.width > mediaContent.height { @@ -38,8 +28,23 @@ class CollectibleDetailImageCell: UICollectionViewCell { // Load image if not only perfroming collectionview layout logic if !layoutOnly { - let maxSize: UInt = 1000000000 // 1000 - MediaProxyService.load(url: mediaContent.mediaURL, to: imageView, withCacheType: mediaContent.isThumbnail ? .temporary : .detail, fallback: UIImage.unknownThumb(), maxAnimatedImageSize: maxSize) + + // If its thumbnail, we don't want it to start animating and then jump back to the start in higher quality + // Set the thumbnail limit to bare minimum so it only loads the first frame, then loads the real image later + let maxSize: UInt = mediaContent.isThumbnail ? 1 : 1000000000 + MediaProxyService.load(url: mediaContent.mediaURL, to: imageView, withCacheType: .temporary, fallback: UIImage.unknownThumb(), maxAnimatedImageSize: maxSize) { [weak self] _ in + + // When imageView is empty, SDImageCache will display its own activity, but not when its filled + // So when we load thumbnail, we have to add our own to display so users know the full is laoding in + if mediaContent.isThumbnail { + self?.activityIndicator.isHidden = false + self?.activityIndicator.startAnimating() + + } else { + self?.activityIndicator.stopAnimating() + self?.activityIndicator.isHidden = true + } + } } setup = true