Load Image from URL

This commit is contained in:
Bilal Syed
2018-03-15 19:00:58 +03:00
parent e1a576fd29
commit 77ebefb650
4 changed files with 31 additions and 8 deletions
+2
View File
@@ -8,11 +8,13 @@
#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>
#import "RNSVGRenderable.h"
#import "RNSVGVBMOS.h"
@interface RNSVGImage : RNSVGRenderable
@property (nonatomic, weak) RCTBridge *bridge;
@property (nonatomic, assign) id src;
@property (nonatomic, strong) NSString* x;
@property (nonatomic, strong) NSString* y;
+16 -2
View File
@@ -9,6 +9,9 @@
#import "RNSVGImage.h"
#import "RCTConvert+RNSVG.h"
#import <React/RCTImageSource.h>
#import <React/RCTImageView.h>
#import <React/RCTImageLoader.h>
#import <React/RCTImageViewManager.h>
#import <React/RCTLog.h>
#import "RNSVGViewBox.h"
@@ -16,6 +19,7 @@
{
CGImageRef _image;
CGFloat _imageRatio;
RCTImageLoaderCancellationBlock _reloadImageCancellationBlock;
}
- (void)setSrc:(id)src
@@ -32,8 +36,18 @@
_imageRatio = 0.0;
}
_image = CGImageRetain([RCTConvert CGImage:src]);
[self invalidate];
RCTImageLoaderCancellationBlock previousCancellationBlock = _reloadImageCancellationBlock;
if (previousCancellationBlock) {
previousCancellationBlock();
_reloadImageCancellationBlock = nil;
}
_reloadImageCancellationBlock = [self.bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:src] callback:^(NSError *error, UIImage *image) {
dispatch_async(dispatch_get_main_queue(), ^{
_image = CGImageRetain(image.CGImage);
[self invalidate];
});
}];
}
- (void)setX:(NSString *)x