mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-21 14:25:14 +00:00
Implement prop extraction for side and alignmentBaseline. Cleanup extractText, fix linting.
This commit is contained in:
@@ -33,31 +33,31 @@ enum AlignmentBaseline {
|
|||||||
center("center"),
|
center("center"),
|
||||||
top("top");
|
top("top");
|
||||||
|
|
||||||
private final String weight;
|
private final String alignment;
|
||||||
|
|
||||||
AlignmentBaseline(String weight) {
|
AlignmentBaseline(String alignment) {
|
||||||
this.weight = weight;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AlignmentBaseline getEnum(String strVal) {
|
public static AlignmentBaseline getEnum(String strVal) {
|
||||||
if (!weightToEnum.containsKey(strVal)) {
|
if (!alignmentToEnum.containsKey(strVal)) {
|
||||||
throw new IllegalArgumentException("Unknown String Value: " + strVal);
|
throw new IllegalArgumentException("Unknown String Value: " + strVal);
|
||||||
}
|
}
|
||||||
return weightToEnum.get(strVal);
|
return alignmentToEnum.get(strVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, AlignmentBaseline> weightToEnum;
|
private static final Map<String, AlignmentBaseline> alignmentToEnum;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final Map<String, AlignmentBaseline> tmpMap = new HashMap<>();
|
final Map<String, AlignmentBaseline> tmpMap = new HashMap<>();
|
||||||
for (final AlignmentBaseline en : AlignmentBaseline.values()) {
|
for (final AlignmentBaseline en : AlignmentBaseline.values()) {
|
||||||
tmpMap.put(en.weight, en);
|
tmpMap.put(en.alignment, en);
|
||||||
}
|
}
|
||||||
weightToEnum = ImmutableMap.copyOf(tmpMap);
|
alignmentToEnum = ImmutableMap.copyOf(tmpMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return weight;
|
return alignment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class FontData {
|
|||||||
private static final String WORD_SPACING = "wordSpacing";
|
private static final String WORD_SPACING = "wordSpacing";
|
||||||
private static final String LETTER_SPACING = "letterSpacing";
|
private static final String LETTER_SPACING = "letterSpacing";
|
||||||
private static final String TEXT_DECORATION = "textDecoration";
|
private static final String TEXT_DECORATION = "textDecoration";
|
||||||
private static final String ALIGNMENT_BASELINE = "alignment-baseline";
|
private static final String ALIGNMENT_BASELINE = "alignmentBaseline";
|
||||||
|
|
||||||
final double fontSize;
|
final double fontSize;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
|
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
|
||||||
import {TextPathAttributes} from '../lib/attributes';
|
import {TextPathAttributes} from '../lib/attributes';
|
||||||
import extractText from '../lib/extract/extractText';
|
import extractText from '../lib/extract/extractText';
|
||||||
@@ -16,15 +15,15 @@ export default class extends Shape {
|
|||||||
static propTypes = textPathProps;
|
static propTypes = textPathProps;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let {children, href, startOffset, ...props} = this.props;
|
let {children, href, startOffset, method, spacing, side, ...props} = this.props;
|
||||||
if (href) {
|
if (href) {
|
||||||
let matched = href.match(idExpReg);
|
let matched = href.match(idExpReg);
|
||||||
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
href = matched[1];
|
href = matched[1];
|
||||||
|
startOffset = `${startOffset || 0}`;
|
||||||
return <RNSVGTextPath
|
return <RNSVGTextPath
|
||||||
href={href}
|
{...{href, startOffset, method, spacing, side}}
|
||||||
{...extractProps({
|
{...extractProps({
|
||||||
...props,
|
...props,
|
||||||
x: null,
|
x: null,
|
||||||
@@ -32,7 +31,6 @@ export default class extends Shape {
|
|||||||
}, this)}
|
}, this)}
|
||||||
{...extractText({
|
{...extractText({
|
||||||
children,
|
children,
|
||||||
startOffset
|
|
||||||
}, true)}
|
}, true)}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ const PathAttributes = {
|
|||||||
|
|
||||||
const TextSpecificAttributes = {
|
const TextSpecificAttributes = {
|
||||||
...RenderableAttributes,
|
...RenderableAttributes,
|
||||||
|
alignmentBaseline: true,
|
||||||
lengthAdjust: true,
|
lengthAdjust: true,
|
||||||
textLength: true,
|
textLength: true,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export function extractFont(props) {
|
|||||||
fontStretch,
|
fontStretch,
|
||||||
textAnchor,
|
textAnchor,
|
||||||
textDecoration,
|
textDecoration,
|
||||||
|
alignmentBaseline,
|
||||||
letterSpacing,
|
letterSpacing,
|
||||||
wordSpacing,
|
wordSpacing,
|
||||||
kerning,
|
kerning,
|
||||||
@@ -73,6 +74,7 @@ export function extractFont(props) {
|
|||||||
fontFamily,
|
fontFamily,
|
||||||
textAnchor,
|
textAnchor,
|
||||||
textDecoration,
|
textDecoration,
|
||||||
|
alignmentBaseline,
|
||||||
letterSpacing,
|
letterSpacing,
|
||||||
wordSpacing,
|
wordSpacing,
|
||||||
kerning,
|
kerning,
|
||||||
@@ -103,13 +105,10 @@ export default function(props, container) {
|
|||||||
y,
|
y,
|
||||||
dx,
|
dx,
|
||||||
dy,
|
dy,
|
||||||
method,
|
|
||||||
spacing,
|
|
||||||
} = props;
|
} = props;
|
||||||
let {
|
let {
|
||||||
rotate,
|
rotate,
|
||||||
children,
|
children
|
||||||
startOffset
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const positionX = parseSVGLengthList(x);
|
const positionX = parseSVGLengthList(x);
|
||||||
@@ -138,7 +137,6 @@ export default function(props, container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const font = extractFont(props);
|
const font = extractFont(props);
|
||||||
startOffset = (startOffset || 0).toString();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
font,
|
font,
|
||||||
@@ -149,8 +147,5 @@ export default function(props, container) {
|
|||||||
rotate,
|
rotate,
|
||||||
deltaX,
|
deltaX,
|
||||||
deltaY,
|
deltaY,
|
||||||
method,
|
|
||||||
spacing,
|
|
||||||
startOffset,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
62
lib/props.js
62
lib/props.js
@@ -48,6 +48,26 @@ const strokeProps = {
|
|||||||
strokeMiterlimit: numberProp
|
strokeMiterlimit: numberProp
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const transformProps = {
|
||||||
|
scale: numberProp,
|
||||||
|
scaleX: numberProp,
|
||||||
|
scaleY: numberProp,
|
||||||
|
rotate: numberProp,
|
||||||
|
rotation: numberProp,
|
||||||
|
translate: numberProp,
|
||||||
|
translateX: numberProp,
|
||||||
|
translateY: numberProp,
|
||||||
|
x: numberProp,
|
||||||
|
y: numberProp,
|
||||||
|
origin: numberProp,
|
||||||
|
originX: numberProp,
|
||||||
|
originY: numberProp,
|
||||||
|
skew: numberProp,
|
||||||
|
skewX: numberProp,
|
||||||
|
skewY: numberProp,
|
||||||
|
transform: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
|
||||||
|
};
|
||||||
|
|
||||||
const pathProps = {
|
const pathProps = {
|
||||||
...fillProps,
|
...fillProps,
|
||||||
...strokeProps,
|
...strokeProps,
|
||||||
@@ -153,19 +173,37 @@ const lengthAdjust = PropTypes.oneOf(['spacing', 'spacingAndGlyphs']);
|
|||||||
*/
|
*/
|
||||||
const textLength = PropTypes.string;
|
const textLength = PropTypes.string;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: alignment-baseline
|
||||||
|
Value: baseline | text-bottom | alphabetic | ideographic | middle | central | mathematical | text-top | bottom | center | top
|
||||||
|
Initial: baseline
|
||||||
|
Applies to: inline-level boxes, flex items, grid items, table cells
|
||||||
|
Inherited: no
|
||||||
|
Percentages: N/A
|
||||||
|
Media: visual
|
||||||
|
Computed value: as specified
|
||||||
|
Canonical order: per grammar
|
||||||
|
Animation type: discrete
|
||||||
|
https://drafts.csswg.org/css-inline/#propdef-alignment-baseline
|
||||||
|
https://svgwg.org/svg2-draft/text.html#AlignmentBaselineProperty
|
||||||
|
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/alignment-baseline
|
||||||
|
*/
|
||||||
|
const alignmentBaseline = PropTypes.oneOf(['baseline', 'text-bottom', 'alphabetic', 'ideographic', 'middle', 'central', 'mathematical', 'text-top', 'bottom', 'center', 'top']);
|
||||||
|
|
||||||
const textSpecificProps = {
|
const textSpecificProps = {
|
||||||
...pathProps,
|
...pathProps,
|
||||||
...fontProps,
|
...fontProps,
|
||||||
|
alignmentBaseline,
|
||||||
lengthAdjust,
|
lengthAdjust,
|
||||||
textLength,
|
textLength,
|
||||||
}
|
};
|
||||||
|
|
||||||
// https://svgwg.org/svg2-draft/text.html#TSpanAttributes
|
// https://svgwg.org/svg2-draft/text.html#TSpanAttributes
|
||||||
const textProps = {
|
const textProps = {
|
||||||
...textSpecificProps,
|
...textSpecificProps,
|
||||||
dx: PropTypes.string,
|
dx: PropTypes.string,
|
||||||
dy: PropTypes.string,
|
dy: PropTypes.string,
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name
|
Name
|
||||||
@@ -231,26 +269,6 @@ const textPathProps = {
|
|||||||
method,
|
method,
|
||||||
spacing,
|
spacing,
|
||||||
side,
|
side,
|
||||||
}
|
|
||||||
|
|
||||||
const transformProps = {
|
|
||||||
scale: numberProp,
|
|
||||||
scaleX: numberProp,
|
|
||||||
scaleY: numberProp,
|
|
||||||
rotate: numberProp,
|
|
||||||
rotation: numberProp,
|
|
||||||
translate: numberProp,
|
|
||||||
translateX: numberProp,
|
|
||||||
translateY: numberProp,
|
|
||||||
x: numberProp,
|
|
||||||
y: numberProp,
|
|
||||||
origin: numberProp,
|
|
||||||
originX: numberProp,
|
|
||||||
originY: numberProp,
|
|
||||||
skew: numberProp,
|
|
||||||
skewX: numberProp,
|
|
||||||
skewY: numberProp,
|
|
||||||
transform: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
Reference in New Issue
Block a user