From 680e001070bde07820e5bcb5cec881882d6aa0e8 Mon Sep 17 00:00:00 2001 From: Minsuk Kang Date: Fri, 6 Jan 2017 14:46:59 -0800 Subject: [PATCH] Image ratio validation and check for iOS --- elements/Image.js | 2 +- ios/Elements/RNSVGImage.m | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/elements/Image.js b/elements/Image.js index 47871e23..75bee192 100644 --- a/elements/Image.js +++ b/elements/Image.js @@ -20,7 +20,7 @@ class Image extends Shape { PropTypes.number, function(props, propName, componentName) { if (Object.keys(props[propName]).length != 1 || - !/^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i.test(props[propName].uri)) { + !/^\s*data:\/\/data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i.test(props[propName].uri)) { return new Error( 'Invalid prop `' + propName + '` supplied to' + ' `' + componentName + '`. Validation failed.' diff --git a/ios/Elements/RNSVGImage.m b/ios/Elements/RNSVGImage.m index 2ef97772..ab0e105e 100644 --- a/ios/Elements/RNSVGImage.m +++ b/ios/Elements/RNSVGImage.m @@ -26,7 +26,14 @@ _src = src; CGImageRelease(_image); RCTImageSource *source = [RCTConvert RCTImageSource:src]; - _imageRatio = source.size.width / source.size.height; + if (source.size.width != 0 && source.size.height != 0) + { + _imageRatio = source.size.width / source.size.height; + } + else + { + _imageRatio = 0.0 + } _image = CGImageRetain([RCTConvert CGImage:src]); [self invalidate]; } @@ -110,7 +117,7 @@ CGFloat rectRatio = rectWidth / rectHeight; CGRect renderRect; - if (imageRatio == rectRatio) { + if (imageRatio == 0.0 || imageRatio == rectRatio) { renderRect = rect; } else if (imageRatio < rectRatio) { renderRect = CGRectMake(0, 0, rectHeight * imageRatio, rectHeight);