Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
2.3 kB · 54 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455diff --git a/ios/ImageView.swift b/ios/ImageView.swiftindex a1f94fe8c039d2649c7144a8db5229efc310c65b..df16ca65b76b762c75f2cff122a4b5450357bfd0 100644--- a/ios/ImageView.swift+++ b/ios/ImageView.swift@@ -52,6 +52,12 @@ public final class ImageView: ExpoView { /// Blurs an asset catalog image, which doesn't go through SDWebImage's transformers. var pendingAssetCatalogBlurTask: Task<Void, Never>? + /**+ Incremented whenever the current load is cancelled or replaced, so a downscale+ finishing on a background queue doesn't render an image the view no longer shows.+ */+ private var loadGeneration = 0+ var contentFit: ContentFit = .cover var contentPosition: ContentPosition = .center@@ -378,6 +384,28 @@ public final class ImageView: ExpoView { contentFit: contentFit ) let imageIdealSize = imageLayoutSize.rounded(.up)++ // Redrawing a large image at its display size takes several milliseconds,+ // so do it off the main thread and render once it's done.+ if allowDownscaling && !bounds.isEmpty && !image.sd_isAnimated+ && shouldDownscale(image: image, toSize: imageIdealSize, scale: scale) {+ sdImageView.animationTransformer = nil+ let generation = loadGeneration+ let layoutSize = imageLayoutSize+ let renderCacheType = ImageCacheType.fromSdCacheType(cacheType)+ DispatchQueue.global(qos: .userInitiated).async { [weak self] in+ let resized = resize(image: image, toSize: imageIdealSize, scale: scale)+ DispatchQueue.main.async {+ guard let self, self.loadGeneration == generation else {+ return+ }+ self.applyContentPosition(contentSize: layoutSize, containerSize: self.frame.size)+ self.renderSourceImage(resized, cacheType: renderCacheType)+ }+ }+ return+ }+ let image = processImage(image, idealSize: imageIdealSize, scale: scale) applyContentPosition(contentSize: imageLayoutSize, containerSize: frame.size) renderSourceImage(image, cacheType: ImageCacheType.fromSdCacheType(cacheType))@@ -883,6 +911,7 @@ public final class ImageView: ExpoView { pendingSVGVariablesTask = nil pendingAssetCatalogBlurTask?.cancel() pendingAssetCatalogBlurTask = nil+ loadGeneration &+= 1 } /**