Skip to content

Commit

Permalink
- fix heavy animated image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Jan 29, 2024
1 parent adee193 commit cde6a33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"location" : "https://github.com/kukai-wallet/kukai-core-swift",
"state" : {
"branch" : "develop",
"revision" : "102e4e263710946b67e3fc403125b7d2f585a179"
"revision" : "b6df6e2744c40ce32760c454f32b391bf84d86af"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit cde6a33

Please sign in to comment.