Image ratio validation and check for iOS

This commit is contained in:
Minsuk Kang
2017-01-06 14:46:59 -08:00
parent 57c1fe5a96
commit 680e001070
2 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -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.'
+9 -2
View File
@@ -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);