mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-21 14:25:14 +00:00
Merge pull request #216 from gpminsuk/master
Data URI support for href in react-native-svg Image tag
This commit is contained in:
@@ -87,7 +87,12 @@ public class ImageShadowNode extends RenderableShadowNode {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mImageRatio = (float)src.getInt("width") / (float)src.getInt("height");
|
if (src.hasKey("width") && src.hasKey("height")) {
|
||||||
|
mImageRatio = (float)src.getInt("width") / (float)src.getInt("height");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mImageRatio = (float)0.0;
|
||||||
|
}
|
||||||
mUri = Uri.parse(uriString);
|
mUri = Uri.parse(uriString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,7 +173,7 @@ public class ImageShadowNode extends RenderableShadowNode {
|
|||||||
float rectRatio = rectWidth / rectHeight;
|
float rectRatio = rectWidth / rectHeight;
|
||||||
RectF renderRect;
|
RectF renderRect;
|
||||||
|
|
||||||
if (mImageRatio == rectRatio) {
|
if (mImageRatio == 0.0 || mImageRatio == rectRatio) {
|
||||||
renderRect = new RectF(rect);
|
renderRect = new RectF(rect);
|
||||||
} else if (mImageRatio < rectRatio) {
|
} else if (mImageRatio < rectRatio) {
|
||||||
renderRect = new RectF(0, 0, (int)(rectHeight * mImageRatio), (int)rectHeight);
|
renderRect = new RectF(0, 0, (int)(rectHeight * mImageRatio), (int)rectHeight);
|
||||||
|
|||||||
@@ -18,7 +18,18 @@ export default class extends Shape {
|
|||||||
y: numberProp,
|
y: numberProp,
|
||||||
width: numberProp.isRequired,
|
width: numberProp.isRequired,
|
||||||
height: numberProp.isRequired,
|
height: numberProp.isRequired,
|
||||||
href: PropTypes.number.isRequired,
|
href: PropTypes.oneOfType([
|
||||||
|
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)) {
|
||||||
|
return new Error(
|
||||||
|
'Invalid prop `' + propName + '` supplied to' +
|
||||||
|
' `' + componentName + '`. Validation failed.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).isRequired,
|
||||||
preserveAspectRatio: PropTypes.string
|
preserveAspectRatio: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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];
|
||||||
}
|
}
|
||||||
@@ -111,7 +118,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