2017-04-13 00:13:44 -04:00
|
|
|
#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) {
|
2017-04-18 10:53:30 -04:00
|
|
|
_source = source;
|
2017-04-13 00:13:44 -04:00
|
|
|
// 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 (_onError) {
|
|
|
|
_onError(@{});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_onLoad) {
|
|
|
|
_onLoad(@{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|