2017-04-13 04:13:44 +00:00
|
|
|
#import "FFFastImageViewManager.h"
|
|
|
|
#import "FFFastImageView.h"
|
|
|
|
|
2017-06-08 21:13:19 +00:00
|
|
|
#import <SDWebImage/SDWebImagePrefetcher.h>
|
|
|
|
|
2017-04-13 04:13:44 +00:00
|
|
|
@implementation FFFastImageViewManager
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE(FastImageView)
|
|
|
|
|
|
|
|
- (FFFastImageView*)view {
|
|
|
|
FFFastImageView* view = [[FFFastImageView alloc] init];
|
|
|
|
view.contentMode = (UIViewContentMode) RCTResizeModeContain;
|
|
|
|
view.clipsToBounds = YES;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2017-07-04 01:58:24 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(source, FFFastImageSource)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(resizeMode, RCTResizeMode)
|
2017-07-24 02:28:35 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadStart, RCTDirectEventBlock)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onFastImageProgress, RCTDirectEventBlock)
|
2017-07-04 01:58:24 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onFastImageError, RCTDirectEventBlock)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoad, RCTDirectEventBlock)
|
2017-07-24 02:28:35 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadEnd, RCTDirectEventBlock)
|
2017-06-20 07:10:56 +00:00
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(preload:(nonnull NSArray<FFFastImageSource *> *)sources)
|
2017-06-08 21:13:19 +00:00
|
|
|
{
|
2017-06-20 07:10:56 +00:00
|
|
|
NSMutableArray *urls = [NSMutableArray arrayWithCapacity:sources.count];
|
|
|
|
|
|
|
|
[sources enumerateObjectsUsingBlock:^(FFFastImageSource * _Nonnull source, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
[source.headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString* header, BOOL *stop) {
|
|
|
|
[[SDWebImageDownloader sharedDownloader] setValue:header forHTTPHeaderField:key];
|
|
|
|
}];
|
|
|
|
[urls setObject:source.uri atIndexedSubscript:idx];
|
|
|
|
}];
|
|
|
|
|
2017-06-08 21:13:19 +00:00
|
|
|
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:urls];
|
|
|
|
}
|
2017-04-13 04:13:44 +00:00
|
|
|
|
|
|
|
@end
|
2017-06-20 07:10:56 +00:00
|
|
|
|