-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
FFFastImageView.m
57 lines (51 loc) · 1.82 KB
/
FFFastImageView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#import "FFFastImageView.h"
@implementation FFFastImageView
- (void)setResizeMode:(RCTResizeMode)resizeMode
{
if (_resizeMode != resizeMode) {
_resizeMode = resizeMode;
self.contentMode = (UIViewContentMode)resizeMode;
}
}
- (void)setSource:(FFFastImageSource *)source {
if (_source != source) {
_source = source;
// Set headers.
[source.headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString* header, BOOL *stop) {
[[SDWebImageDownloader sharedDownloader] setValue:header forHTTPHeaderField:key];
}];
// Set priority.
SDWebImageOptions options = 0;
options |= SDWebImageRetryFailed;
switch (source.priority) {
case FFFPriorityLow:
options |= SDWebImageLowPriority;
break;
case FFFPriorityNormal:
// Priority is normal by default.
break;
case FFFPriorityHigh:
options |= SDWebImageHighPriority;
break;
}
// Load the new source.
[self sd_setImageWithURL:source.uri
placeholderImage:nil
options:options
completed:^(UIImage *image,
NSError *error,
SDImageCacheType cacheType,
NSURL *imageURL) {
if (error) {
if (_onFastImageError) {
_onFastImageError(@{});
}
} else {
if (_onFastImageLoad) {
_onFastImageLoad(@{});
}
}
}];
}
}
@end