diff --git a/android/src/main/java/com/horcrux/svg/ImageShadowNode.java b/android/src/main/java/com/horcrux/svg/ImageShadowNode.java index 0f3a1cb4..287ae357 100644 --- a/android/src/main/java/com/horcrux/svg/ImageShadowNode.java +++ b/android/src/main/java/com/horcrux/svg/ImageShadowNode.java @@ -32,6 +32,7 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.common.ReactConstants; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper; +import com.facebook.react.views.imagehelper.ImageSource; import java.util.concurrent.atomic.AtomicBoolean; @@ -50,6 +51,7 @@ class ImageShadowNode extends RenderableShadowNode { private String mW; private String mH; private Uri mUri; + private String uriString; private int mImageWidth; private int mImageHeight; private String mAlign; @@ -90,7 +92,7 @@ class ImageShadowNode extends RenderableShadowNode { @ReactProp(name = "src") public void setSrc(@Nullable ReadableMap src) { if (src != null) { - String uriString = src.getString("uri"); + uriString = src.getString("uri"); if (uriString == null || uriString.isEmpty()) { //TODO: give warning about this @@ -147,7 +149,9 @@ class ImageShadowNode extends RenderableShadowNode { @Override public void draw(final Canvas canvas, final Paint paint, final float opacity) { if (!mLoading.get()) { - final ImageRequest request = ImageRequestBuilder.newBuilderWithSource(mUri).build(); + final ImageSource imageSource = new ImageSource(getThemedContext(), uriString); + + final ImageRequest request = ImageRequestBuilder.newBuilderWithSource(imageSource.getUri()).build(); if (Fresco.getImagePipeline().isInBitmapMemoryCache(request)) { tryRender(request, canvas, paint, opacity * mOpacity); } else { @@ -170,7 +174,10 @@ class ImageShadowNode extends RenderableShadowNode { @Override public void onNewResultImpl(Bitmap bitmap) { mLoading.set(false); - bitmapTryRender(bitmap, canvas, paint, opacity * mOpacity); + SvgViewShadowNode shadowNode = getSvgShadowNode(); + if(shadowNode != null) { + shadowNode.markUpdated(); + } } @Override diff --git a/ios/Elements/RNSVGImage.h b/ios/Elements/RNSVGImage.h index 377d4074..303bdd29 100644 --- a/ios/Elements/RNSVGImage.h +++ b/ios/Elements/RNSVGImage.h @@ -8,11 +8,13 @@ #import +#import #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; diff --git a/ios/Elements/RNSVGImage.m b/ios/Elements/RNSVGImage.m index 64c313f4..0af09143 100644 --- a/ios/Elements/RNSVGImage.m +++ b/ios/Elements/RNSVGImage.m @@ -9,6 +9,9 @@ #import "RNSVGImage.h" #import "RCTConvert+RNSVG.h" #import +#import +#import +#import #import #import "RNSVGViewBox.h" @@ -16,6 +19,7 @@ { CGImageRef _image; CGSize _imageSize; + RCTImageLoaderCancellationBlock _reloadImageCancellationBlock; } - (void)setSrc:(id)src @@ -32,7 +36,19 @@ } else { _imageSize = CGSizeMake(CGImageGetWidth(_image), CGImageGetHeight(_image)); } - [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 diff --git a/ios/ViewManagers/RNSVGImageManager.m b/ios/ViewManagers/RNSVGImageManager.m index 8df08ae8..5f965e3a 100644 --- a/ios/ViewManagers/RNSVGImageManager.m +++ b/ios/ViewManagers/RNSVGImageManager.m @@ -17,7 +17,10 @@ RCT_EXPORT_MODULE() - (RNSVGRenderable *)node { - return [RNSVGImage new]; + RNSVGImage *svgImage = [RNSVGImage new]; + svgImage.bridge = self.bridge; + + return svgImage; } RCT_EXPORT_VIEW_PROPERTY(x, NSString)