react-native-fast-image 8.6.18 → 8.6.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -236,18 +236,33 @@
|
|
|
236
236
|
|
|
237
237
|
- (void) downloadImage: (FFFastImageSource*)source options: (SDWebImageOptions)options context: (SDWebImageContext*)context {
|
|
238
238
|
__weak typeof(self) weakSelf = self; // Always use a weak reference to self in blocks
|
|
239
|
+
// Most images have no onProgress, so only ask SDWebImage for progress when
|
|
240
|
+
// there's a handler as the load starts. A handler added while loading is
|
|
241
|
+
// used from the next load.
|
|
242
|
+
SDImageLoaderProgressBlock progress = nil;
|
|
243
|
+
if (self.onFastImageProgress) {
|
|
244
|
+
progress = ^(NSInteger receivedSize, NSInteger expectedSize, NSURL* _Nullable targetURL) {
|
|
245
|
+
// SDWebImage calls this on its download queue, while React Native
|
|
246
|
+
// sets onFastImageProgress (and deallocates the view) on the main
|
|
247
|
+
// queue. Read and call it there, so it can't change or be released
|
|
248
|
+
// in between (EXC_BAD_ACCESS).
|
|
249
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
250
|
+
RCTDirectEventBlock onProgress = weakSelf.onFastImageProgress;
|
|
251
|
+
if (onProgress) {
|
|
252
|
+
onProgress(@{
|
|
253
|
+
@"loaded": @(receivedSize),
|
|
254
|
+
@"total": @(expectedSize)
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
}
|
|
239
260
|
[self sd_setImageWithURL: _source.url
|
|
240
261
|
placeholderImage: _defaultSource
|
|
241
262
|
options: options
|
|
242
263
|
context: context
|
|
243
|
-
progress:
|
|
244
|
-
|
|
245
|
-
weakSelf.onFastImageProgress(@{
|
|
246
|
-
@"loaded": @(receivedSize),
|
|
247
|
-
@"total": @(expectedSize)
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
} completed: ^(UIImage* _Nullable image,
|
|
264
|
+
progress: progress
|
|
265
|
+
completed: ^(UIImage* _Nullable image,
|
|
251
266
|
NSError* _Nullable error,
|
|
252
267
|
SDImageCacheType cacheType,
|
|
253
268
|
NSURL* _Nullable imageURL) {
|