From 9df76e5668bffbd79c0c4bcfd9c610d8c2b9d7af Mon Sep 17 00:00:00 2001 From: Horcrux Date: Tue, 4 Apr 2017 10:45:54 +0800 Subject: [PATCH 1/5] Use Image.propTypes.source as href propType --- .../main/java/com/horcrux/svg/ImageShadowNode.java | 7 +++---- elements/Image.js | 14 ++------------ ios/Elements/RNSVGImage.m | 12 +++++------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/ImageShadowNode.java b/android/src/main/java/com/horcrux/svg/ImageShadowNode.java index e454a2c0..14b470b7 100644 --- a/android/src/main/java/com/horcrux/svg/ImageShadowNode.java +++ b/android/src/main/java/com/horcrux/svg/ImageShadowNode.java @@ -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); diff --git a/elements/Image.js b/elements/Image.js index 65f1d348..673ab9ca 100644 --- a/elements/Image.js +++ b/elements/Image.js @@ -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 }; diff --git a/ios/Elements/RNSVGImage.m b/ios/Elements/RNSVGImage.m index d5d714c7..97ac9f62 100644 --- a/ios/Elements/RNSVGImage.m +++ b/ios/Elements/RNSVGImage.m @@ -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); From e3b2f4c71add751c29eaa572bb8f0555aca305fb Mon Sep 17 00:00:00 2001 From: Horcrux Date: Tue, 4 Apr 2017 11:56:38 +0800 Subject: [PATCH 2/5] Fix Polygon and Polyline --- elements/Polygon.js | 3 ++- elements/Polyline.js | 3 ++- lib/extract/extractPolyPoints.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 lib/extract/extractPolyPoints.js diff --git a/elements/Polygon.js b/elements/Polygon.js index 19d463d7..7e55f0b0 100644 --- a/elements/Polygon.js +++ b/elements/Polygon.js @@ -1,6 +1,7 @@ import React, {Component, PropTypes} from 'react'; import Path from './Path'; import {pathProps} from '../lib/props'; +import extractPolyPoints from '../lib/extract/extractPolyPoints'; export default class extends Component{ static displayName = 'Polygon'; @@ -26,7 +27,7 @@ export default class extends Component{ return {this.root = ele;}} {...this.props} - d={`M${points.trim().replace(/\s+/g, 'L')}z`} + d={`M${extractPolyPoints(points)}z`} />; } } diff --git a/elements/Polyline.js b/elements/Polyline.js index d59b62da..a582aee2 100644 --- a/elements/Polyline.js +++ b/elements/Polyline.js @@ -1,6 +1,7 @@ import React, {Component, PropTypes} from 'react'; import Path from './Path'; import {pathProps} from '../lib/props'; +import extractPolyPoints from '../lib/extract/extractPolyPoints'; export default class extends Component{ static displayName = 'Polyline'; @@ -26,7 +27,7 @@ export default class extends Component{ return {this.root = ele;}} {...this.props} - d={`M${points.trim().replace(/\s+/g, 'L')}`} + d={`M${extractPolyPoints(points)}`} />; } } diff --git a/lib/extract/extractPolyPoints.js b/lib/extract/extractPolyPoints.js new file mode 100644 index 00000000..1c3ba4be --- /dev/null +++ b/lib/extract/extractPolyPoints.js @@ -0,0 +1,4 @@ + +export default function (polyPoints) { + return polyPoints.replace(/-/, ' -').split(/(?:\s+|\s*,)\s*/g).join(' '); +} From ea1a87887e930f56eed1b2177e0c35d17d735478 Mon Sep 17 00:00:00 2001 From: Horcrux Date: Tue, 4 Apr 2017 11:59:59 +0800 Subject: [PATCH 3/5] Fix polypoints RegExp --- lib/extract/extractPolyPoints.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extract/extractPolyPoints.js b/lib/extract/extractPolyPoints.js index 1c3ba4be..56c573f9 100644 --- a/lib/extract/extractPolyPoints.js +++ b/lib/extract/extractPolyPoints.js @@ -1,4 +1,4 @@ export default function (polyPoints) { - return polyPoints.replace(/-/, ' -').split(/(?:\s+|\s*,)\s*/g).join(' '); + return polyPoints.replace(/-/, ' -').split(/(?:\s+|\s*,\s*)/g).join(' '); } From bbe1964a4285030ab4703db765129c0ba262c591 Mon Sep 17 00:00:00 2001 From: Horcrux Date: Tue, 4 Apr 2017 12:30:53 +0800 Subject: [PATCH 4/5] Fix #284 --- lib/extract/extractText.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extract/extractText.js b/lib/extract/extractText.js index 5d8fb98c..b7e628d9 100644 --- a/lib/extract/extractText.js +++ b/lib/extract/extractText.js @@ -105,7 +105,7 @@ export default function(props, container) { content = childrenString; children = null; } - } else if (Children.count(children) > 1) { + } else if (Children.count(children) > 1 || Array.isArray(children)) { children = Children.map(children, child => { if (typeof child === 'string' || typeof child === 'number') { return {child.toString()}; From b2bb3c31b4684c0c4475cc28f76cf521b441191b Mon Sep 17 00:00:00 2001 From: Horcrux Date: Tue, 4 Apr 2017 12:47:26 +0800 Subject: [PATCH 5/5] Bump version to 5.1.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a810f40d..916e8e96 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "5.1.6", + "version": "5.1.7", "name": "react-native-svg", "description": "SVG library for react-native", "repository": {