Permalink
Browse files

Providing an API to load assets from a different directory

Differential Revision: D6368586

fbshipit-source-id: 2a79ba45de3d9c95d0b1b296c9e1ae35cbd33c36
  • Loading branch information...
Yujie Liu authored and facebook-github-bot committed Dec 8, 2017
1 parent 5ee27ff commit 8f9b291224d1ca57a5f90200ec4687abb4706f4b
Showing with 32 additions and 0 deletions.
  1. +15 −0 Libraries/Image/RCTImageLoader.h
  2. +17 −0 Libraries/Image/RCTImageLoader.m
@@ -38,6 +38,18 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
@end
/**
* If available, RCTImageRedirectProtocol is invoked before loading an asset.
* Implementation should return either a new URL or nil when redirection is
* not needed.
*/
@protocol RCTImageRedirectProtocol
- (NSURL *)redirectAssetsURL:(NSURL *)URL;
@end
@interface UIImage (React)
@property (nonatomic, copy) CAKeyframeAnimation *reactKeyframeAnimation;
@@ -71,6 +83,9 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
*/
@property (nonatomic, assign) NSUInteger maxConcurrentDecodingBytes;
- (instancetype)init;
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate NS_DESIGNATED_INITIALIZER;
/**
* Loads the specified image at the highest available resolution.
* Can be called from any thread, will call back on an unspecified thread.
@@ -48,12 +48,26 @@ @implementation RCTImageLoader
NSMutableArray *_pendingDecodes;
NSInteger _scheduledDecodes;
NSUInteger _activeBytes;
__weak id<RCTImageRedirectProtocol> _redirectDelegate;
}
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE()
- (instancetype)init
{
return [self initWithRedirectDelegate:nil];
}
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate
{
if (self = [super init]) {
_redirectDelegate = redirectDelegate;
}
return self;
}
- (void)setUp
{
// Set defaults
@@ -316,6 +330,9 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
if (request.URL.fileURL && request.URL.pathExtension.length == 0) {
mutableRequest.URL = [request.URL URLByAppendingPathExtension:@"png"];
}
if (_redirectDelegate != nil) {
mutableRequest.URL = [_redirectDelegate redirectAssetsURL:mutableRequest.URL];
}
request = mutableRequest;
}

0 comments on commit 8f9b291

Please sign in to comment.