From 68eeb5e6daa832dda5d6c9b2b3f15883419bee48 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Tue, 15 Aug 2017 13:31:42 +0300 Subject: [PATCH] Improve numberProp and numberArrayProp PropTypes usage. Implement "normal" relative unit in java. --- .../main/java/com/horcrux/svg/PropHelper.java | 2 +- lib/props.js | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/PropHelper.java b/android/src/main/java/com/horcrux/svg/PropHelper.java index 3eb1aded..4ddb0a7c 100644 --- a/android/src/main/java/com/horcrux/svg/PropHelper.java +++ b/android/src/main/java/com/horcrux/svg/PropHelper.java @@ -95,7 +95,7 @@ class PropHelper { length = length.trim(); int stringLength = length.length(); int percentIndex = stringLength - 1; - if (stringLength == 0) { + if (stringLength == 0 || length.equals("normal")) { return offset; } else if (length.codePointAt(percentIndex) == '%') { return Double.valueOf(length.substring(0, percentIndex)) / 100 * relative + offset; diff --git a/lib/props.js b/lib/props.js index 282fa349..251424ce 100644 --- a/lib/props.js +++ b/lib/props.js @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'; import {PanResponder} from 'react-native'; const numberProp = PropTypes.oneOfType([PropTypes.string, PropTypes.number]); +const numberArrayProp = PropTypes.oneOfType([PropTypes.arrayOf(numberProp), numberProp]); const touchableProps = { disabled: PropTypes.bool, @@ -41,7 +42,7 @@ const strokeProps = { stroke: PropTypes.string, strokeWidth: numberProp, strokeOpacity: numberProp, - strokeDasharray: PropTypes.oneOfType([PropTypes.arrayOf(numberProp), PropTypes.string]), + strokeDasharray: numberArrayProp, strokeDashoffset: numberProp, strokeLinecap: PropTypes.oneOf(['butt', 'square', 'round']), strokeLinejoin: PropTypes.oneOf(['miter', 'bevel', 'round']), @@ -96,7 +97,7 @@ const fontStretch = PropTypes.oneOf(['normal', 'wider', 'narrower', 'ultra-conde // | | | | inherit // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-size -const fontSize = PropTypes.string; +const fontSize = numberProp; // [[ | ],]* [ | ] | inherit // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-family @@ -132,15 +133,15 @@ const textDecoration = PropTypes.oneOf(['none', 'underline', 'overline', 'line-t // normal | | inherit // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/letter-spacing -const letterSpacing = PropTypes.string; +const letterSpacing = numberProp; // normal | | inherit // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/word-spacing -const wordSpacing = PropTypes.string; +const wordSpacing = numberProp; // auto | | inherit // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/kerning -const kerning = PropTypes.string; +const kerning = numberProp; /* Name: font-variant-ligatures @@ -195,7 +196,7 @@ const lengthAdjust = PropTypes.oneOf(['spacing', 'spacingAndGlyphs']); https://svgwg.org/svg2-draft/text.html#TextElementTextLengthAttribute https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/textLength */ -const textLength = PropTypes.string; +const textLength = numberProp; /* 2.2. Transverse Box Alignment: the vertical-align property @@ -218,7 +219,7 @@ const textLength = PropTypes.string; https://www.w3.org/TR/css-inline-3/#transverse-alignment https://drafts.csswg.org/css-inline/#propdef-vertical-align */ -const verticalAlign = PropTypes.string; +const verticalAlign = numberProp; /* Name: alignment-baseline @@ -258,7 +259,7 @@ const alignmentBaseline = PropTypes.oneOf(['baseline', 'text-bottom', 'alphabeti https://www.w3.org/TR/css-inline-3/#propdef-baseline-shift */ -const baselineShift = PropTypes.oneOfType([PropTypes.oneOf(['sub', 'super', 'baseline']), PropTypes.arrayOf(numberProp), PropTypes.string]); +const baselineShift = PropTypes.oneOfType([PropTypes.oneOf(['sub', 'super', 'baseline']), PropTypes.arrayOf(numberProp), numberProp]); /* 6.12. Low-level font feature settings control: the font-feature-settings property @@ -375,8 +376,8 @@ const textSpecificProps = { // https://svgwg.org/svg2-draft/text.html#TSpanAttributes const textProps = { ...textSpecificProps, - dx: PropTypes.string, - dy: PropTypes.string, + dx: numberArrayProp, + dy: numberArrayProp, }; /* @@ -404,7 +405,7 @@ const side = PropTypes.oneOf(['left', 'right']); https://svgwg.org/svg2-draft/text.html#TextPathElementStartOffsetAttribute https://developer.mozilla.org/en/docs/Web/SVG/Element/textPath */ -const startOffset = PropTypes.string; +const startOffset = numberProp; /* Name