mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-02 14:50:43 +00:00
Image ratio validation and check for iOS
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ class Image extends Shape {
|
|||||||
PropTypes.number,
|
PropTypes.number,
|
||||||
function(props, propName, componentName) {
|
function(props, propName, componentName) {
|
||||||
if (Object.keys(props[propName]).length != 1 ||
|
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(
|
return new Error(
|
||||||
'Invalid prop `' + propName + '` supplied to' +
|
'Invalid prop `' + propName + '` supplied to' +
|
||||||
' `' + componentName + '`. Validation failed.'
|
' `' + componentName + '`. Validation failed.'
|
||||||
|
|||||||
@@ -26,7 +26,14 @@
|
|||||||
_src = src;
|
_src = src;
|
||||||
CGImageRelease(_image);
|
CGImageRelease(_image);
|
||||||
RCTImageSource *source = [RCTConvert RCTImageSource:src];
|
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]);
|
_image = CGImageRetain([RCTConvert CGImage:src]);
|
||||||
[self invalidate];
|
[self invalidate];
|
||||||
}
|
}
|
||||||
@@ -110,7 +117,7 @@
|
|||||||
CGFloat rectRatio = rectWidth / rectHeight;
|
CGFloat rectRatio = rectWidth / rectHeight;
|
||||||
CGRect renderRect;
|
CGRect renderRect;
|
||||||
|
|
||||||
if (imageRatio == rectRatio) {
|
if (imageRatio == 0.0 || imageRatio == rectRatio) {
|
||||||
renderRect = rect;
|
renderRect = rect;
|
||||||
} else if (imageRatio < rectRatio) {
|
} else if (imageRatio < rectRatio) {
|
||||||
renderRect = CGRectMake(0, 0, rectHeight * imageRatio, rectHeight);
|
renderRect = CGRectMake(0, 0, rectHeight * imageRatio, rectHeight);
|
||||||
|
|||||||
Reference in New Issue
Block a user