mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 09:12:02 +00:00
1076f4a172
Summary: public Added RCTDataRequestHandler, which is responsible for loading data URLs. This moves the logic for data URL handling out of RCTImageDownloader (no longer needed) and into the RCTNetwork library, where it makes more sense. This also means that it is now possible to load data URLs via XHR, and use them for purposes other than just images. Reviewed By: javache Differential Revision: D2540964 fb-gh-sync-id: 4f0418bd6b9186f047cc8297276bb970795af104
55 lines
1.4 KiB
Objective-C
55 lines
1.4 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#import "RCTXCAssetImageLoader.h"
|
|
|
|
#import "RCTUtils.h"
|
|
|
|
@implementation RCTXCAssetImageLoader
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
- (BOOL)canLoadImageURL:(NSURL *)requestURL
|
|
{
|
|
return RCTIsXCAssetURL(requestURL);
|
|
}
|
|
|
|
- (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL size:(CGSize)size scale:(CGFloat)scale resizeMode:(UIViewContentMode)resizeMode progressHandler:(RCTImageLoaderProgressBlock)progressHandler completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
|
|
{
|
|
__block BOOL cancelled = NO;
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (cancelled) {
|
|
return;
|
|
}
|
|
|
|
NSString *imageName = RCTBundlePathForURL(imageURL);
|
|
UIImage *image = [UIImage imageNamed:imageName];
|
|
if (image) {
|
|
if (progressHandler) {
|
|
progressHandler(1, 1);
|
|
}
|
|
|
|
if (completionHandler) {
|
|
completionHandler(nil, image);
|
|
}
|
|
} else {
|
|
if (completionHandler) {
|
|
NSString *message = [NSString stringWithFormat:@"Could not find image named %@", imageName];
|
|
completionHandler(RCTErrorWithMessage(message), nil);
|
|
}
|
|
}
|
|
});
|
|
|
|
return ^{
|
|
cancelled = YES;
|
|
};
|
|
}
|
|
|
|
@end
|