mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 06:07:41 +00:00
Load Image from URL
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user