2015-09-02 15:25:10 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
2015-09-02 15:25:10 +00:00
|
|
|
*
|
2017-05-06 03:50:47 +00:00
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-09-02 15:25:10 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTImageLoaderHelpers.h"
|
|
|
|
|
|
|
|
@implementation RCTConcreteImageURLLoader
|
|
|
|
{
|
|
|
|
RCTImageURLLoaderCanLoadImageURLHandler _canLoadImageURLHandler;
|
|
|
|
RCTImageURLLoaderLoadImageURLHandler _loadImageURLHandler;
|
|
|
|
float _priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *)moduleName
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithPriority:(float)priority canLoadImageURLHandler:(RCTImageURLLoaderCanLoadImageURLHandler)canLoadImageURLHandler loadImageURLHandler:(RCTImageURLLoaderLoadImageURLHandler)loadImageURLHandler
|
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
|
|
|
_canLoadImageURLHandler = [canLoadImageURLHandler copy];
|
|
|
|
_loadImageURLHandler = [loadImageURLHandler copy];
|
|
|
|
_priority = priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canLoadImageURL:(NSURL *)requestURL
|
|
|
|
{
|
|
|
|
return _canLoadImageURLHandler(requestURL);
|
|
|
|
}
|
|
|
|
|
2016-09-27 13:07:29 +00:00
|
|
|
- (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
|
|
|
|
size:(CGSize)size
|
|
|
|
scale:(CGFloat)scale
|
|
|
|
resizeMode:(RCTResizeMode)resizeMode
|
|
|
|
progressHandler:(RCTImageLoaderProgressBlock)progressHandler
|
|
|
|
partialLoadHandler:(__unused RCTImageLoaderPartialLoadBlock)partialLoadHandler
|
|
|
|
completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
|
2015-09-02 15:25:10 +00:00
|
|
|
{
|
|
|
|
return _loadImageURLHandler(imageURL, size, scale, resizeMode, progressHandler, completionHandler);
|
|
|
|
}
|
|
|
|
|
2015-10-19 16:04:54 +00:00
|
|
|
- (float)loaderPriority
|
2015-09-02 15:25:10 +00:00
|
|
|
{
|
|
|
|
return _priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTConcreteImageDecoder
|
|
|
|
{
|
2015-10-19 16:04:54 +00:00
|
|
|
RCTImageDataDecoderCanDecodeImageDataHandler _canDecodeImageDataHandler;
|
|
|
|
RCTImageDataDecoderDecodeImageDataHandler _decodeImageDataHandler;
|
2015-09-02 15:25:10 +00:00
|
|
|
float _priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *)moduleName
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-10-19 16:04:54 +00:00
|
|
|
- (instancetype)initWithPriority:(float)priority canDecodeImageDataHandler:(RCTImageDataDecoderCanDecodeImageDataHandler)canDecodeImageDataHandler decodeImageDataHandler:(RCTImageDataDecoderDecodeImageDataHandler)decodeImageDataHandler
|
2015-09-02 15:25:10 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
|
|
|
_canDecodeImageDataHandler = [canDecodeImageDataHandler copy];
|
|
|
|
_decodeImageDataHandler = [decodeImageDataHandler copy];
|
|
|
|
_priority = priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canDecodeImageData:(NSData *)imageData
|
|
|
|
{
|
|
|
|
return _canDecodeImageDataHandler(imageData);
|
|
|
|
}
|
|
|
|
|
2016-01-20 19:03:22 +00:00
|
|
|
- (RCTImageLoaderCancellationBlock)decodeImageData:(NSData *)imageData size:(CGSize)size scale:(CGFloat)scale resizeMode:(RCTResizeMode)resizeMode completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
|
2015-09-02 15:25:10 +00:00
|
|
|
{
|
|
|
|
return _decodeImageDataHandler(imageData, size, scale, resizeMode, completionHandler);
|
|
|
|
}
|
|
|
|
|
2015-10-19 16:04:54 +00:00
|
|
|
- (float)decoderPriority
|
2015-09-02 15:25:10 +00:00
|
|
|
{
|
|
|
|
return _priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|