mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-23 11:16:42 +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,
|
||||
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.'
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user