mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 14:05:09 +00:00
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
|
|
import {TextPathAttributes} from '../lib/attributes';
|
|
import extractText from '../lib/extract/extractText';
|
|
import Shape from './Shape';
|
|
import {pathProps, fontProps, numberProp} from '../lib/props';
|
|
import extractProps from '../lib/extract/extractProps';
|
|
import TSpan from './TSpan';
|
|
|
|
const idExpReg = /^#(.+)$/;
|
|
|
|
export default class extends Shape {
|
|
static displayName = 'Span';
|
|
|
|
static propTypes = {
|
|
...pathProps,
|
|
...fontProps,
|
|
href: PropTypes.string.isRequired,
|
|
method: PropTypes.oneOf(['align', 'stretch']),
|
|
spacing: PropTypes.oneOf(['auto', 'exact']),
|
|
startOffset: PropTypes.string
|
|
};
|
|
|
|
render() {
|
|
let {children, href, startOffset, ...props} = this.props;
|
|
if (href) {
|
|
let matched = href.match(idExpReg);
|
|
|
|
if (matched) {
|
|
href = matched[1];
|
|
|
|
return <RNSVGTextPath
|
|
href={href}
|
|
{...extractProps({
|
|
...props,
|
|
x: null,
|
|
y: null
|
|
}, this)}
|
|
{...extractText({
|
|
children,
|
|
startOffset
|
|
}, true)}
|
|
/>;
|
|
}
|
|
}
|
|
|
|
console.warn('Invalid `href` prop for `TextPath` element, expected a href like `"#id"`, but got: "' + props.href + '"');
|
|
return <TSpan>{children}</TSpan>;
|
|
}
|
|
|
|
}
|
|
|
|
const RNSVGTextPath = createReactNativeComponentClass({
|
|
validAttributes: TextPathAttributes,
|
|
uiViewClassName: 'RNSVGTextPath'
|
|
});
|