mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-28 21:03:51 +00:00
Use Image.propTypes.source as href propType
This commit is contained in:
@@ -89,9 +89,8 @@ public class ImageShadowNode extends RenderableShadowNode {
|
||||
|
||||
if (src.hasKey("width") && src.hasKey("height")) {
|
||||
mImageRatio = (float)src.getInt("width") / (float)src.getInt("height");
|
||||
}
|
||||
else {
|
||||
mImageRatio = (float)0.0;
|
||||
} else {
|
||||
mImageRatio = 0f;
|
||||
}
|
||||
mUri = Uri.parse(uriString);
|
||||
}
|
||||
@@ -173,7 +172,7 @@ public class ImageShadowNode extends RenderableShadowNode {
|
||||
float rectRatio = rectWidth / rectHeight;
|
||||
RectF renderRect;
|
||||
|
||||
if (mImageRatio == 0.0 || mImageRatio == rectRatio) {
|
||||
if (mImageRatio == 0f || mImageRatio == rectRatio) {
|
||||
renderRect = new RectF(rect);
|
||||
} else if (mImageRatio < rectRatio) {
|
||||
renderRect = new RectF(0, 0, (int)(rectHeight * mImageRatio), (int)rectHeight);
|
||||
|
||||
+2
-12
@@ -1,4 +1,5 @@
|
||||
import React, {PropTypes} from 'react';
|
||||
import { Image } from 'react-native';
|
||||
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/src/renderers/native/createReactNativeComponentClass';
|
||||
import {ImageAttributes} from '../lib/attributes';
|
||||
import {numberProp, touchableProps, responderProps} from '../lib/props';
|
||||
@@ -18,18 +19,7 @@ export default class extends Shape {
|
||||
y: numberProp,
|
||||
width: numberProp.isRequired,
|
||||
height: numberProp.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,
|
||||
href: Image.propTypes.source,
|
||||
preserveAspectRatio: PropTypes.string
|
||||
};
|
||||
|
||||
|
||||
@@ -26,14 +26,12 @@
|
||||
_src = src;
|
||||
CGImageRelease(_image);
|
||||
RCTImageSource *source = [RCTConvert RCTImageSource:src];
|
||||
if (source.size.width != 0 && source.size.height != 0)
|
||||
{
|
||||
if (source.size.width != 0 && source.size.height != 0) {
|
||||
_imageRatio = source.size.width / source.size.height;
|
||||
} else {
|
||||
_imageRatio = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageRatio = 0.0
|
||||
}
|
||||
|
||||
_image = CGImageRetain([RCTConvert CGImage:src]);
|
||||
[self invalidate];
|
||||
}
|
||||
@@ -118,7 +116,7 @@
|
||||
CGFloat rectRatio = rectWidth / rectHeight;
|
||||
CGRect renderRect;
|
||||
|
||||
if (imageRatio == 0.0 || imageRatio == rectRatio) {
|
||||
if (!imageRatio || imageRatio == rectRatio) {
|
||||
renderRect = rect;
|
||||
} else if (imageRatio < rectRatio) {
|
||||
renderRect = CGRectMake(0, 0, rectHeight * imageRatio, rectHeight);
|
||||
|
||||
Reference in New Issue
Block a user