File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,18 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
38
38
39
39
@end
40
40
41
+ /* *
42
+ * If available, RCTImageRedirectProtocol is invoked before loading an asset.
43
+ * Implementation should return either a new URL or nil when redirection is
44
+ * not needed.
45
+ */
46
+
47
+ @protocol RCTImageRedirectProtocol
48
+
49
+ - (NSURL *)redirectAssetsURL : (NSURL *)URL ;
50
+
51
+ @end
52
+
41
53
@interface UIImage (React)
42
54
43
55
@property (nonatomic , copy ) CAKeyframeAnimation *reactKeyframeAnimation;
@@ -71,6 +83,9 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
71
83
*/
72
84
@property (nonatomic , assign ) NSUInteger maxConcurrentDecodingBytes;
73
85
86
+ - (instancetype )init ;
87
+ - (instancetype )initWithRedirectDelegate : (id <RCTImageRedirectProtocol>)redirectDelegate NS_DESIGNATED_INITIALIZER;
88
+
74
89
/* *
75
90
* Loads the specified image at the highest available resolution.
76
91
* Can be called from any thread, will call back on an unspecified thread.
Original file line number Diff line number Diff line change @@ -48,12 +48,26 @@ @implementation RCTImageLoader
48
48
NSMutableArray *_pendingDecodes;
49
49
NSInteger _scheduledDecodes;
50
50
NSUInteger _activeBytes;
51
+ __weak id <RCTImageRedirectProtocol> _redirectDelegate;
51
52
}
52
53
53
54
@synthesize bridge = _bridge;
54
55
55
56
RCT_EXPORT_MODULE ()
56
57
58
+ - (instancetype )init
59
+ {
60
+ return [self initWithRedirectDelegate: nil ];
61
+ }
62
+
63
+ - (instancetype )initWithRedirectDelegate : (id <RCTImageRedirectProtocol>)redirectDelegate
64
+ {
65
+ if (self = [super init ]) {
66
+ _redirectDelegate = redirectDelegate;
67
+ }
68
+ return self;
69
+ }
70
+
57
71
- (void )setUp
58
72
{
59
73
// Set defaults
@@ -316,6 +330,9 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
316
330
if (request.URL .fileURL && request.URL .pathExtension .length == 0 ) {
317
331
mutableRequest.URL = [request.URL URLByAppendingPathExtension: @" png" ];
318
332
}
333
+ if (_redirectDelegate != nil ) {
334
+ mutableRequest.URL = [_redirectDelegate redirectAssetsURL: mutableRequest.URL];
335
+ }
319
336
request = mutableRequest;
320
337
}
321
338
You can’t perform that action at this time.
0 commit comments