Add uri loading

This commit is contained in:
Minsuk Kang
2017-01-05 21:56:38 -08:00
parent a194ade11e
commit c3a736b1b9
2 changed files with 13 additions and 3 deletions

View File

@@ -87,7 +87,12 @@ public class ImageShadowNode extends PathShadowNode {
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);
} }
} }
@@ -170,7 +175,7 @@ public class ImageShadowNode extends PathShadowNode {
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);

View File

@@ -16,7 +16,12 @@ class Image 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,
PropTypes.shape({
uri: PropTypes.string.isRequired
})
]).isRequired,
preserveAspectRatio: PropTypes.string preserveAspectRatio: PropTypes.string
}; };