Files
react-native-svg/elements/TextPath.js
2017-01-10 12:30:48 +08:00

56 lines
1.6 KiB
JavaScript

import React, {PropTypes} from 'react';
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/src/renderers/native/createReactNativeComponentClass';
import {TextPathAttributes} from '../lib/attributes';
import extractText from '../lib/extract/extractText';
import Shape from './Shape';
import {pathProps, fontProps, numberProp} from '../lib/props';
import TSpan from './TSpan';
const idExpReg = /^#(.+)$/;
class TextPath extends Shape {
static displayName = 'Span';
static propTypes = {
...pathProps,
...fontProps,
href: PropTypes.string.isRequired,
startOffset: numberProp
};
render() {
let {children, href, startOffset, ...props} = this.props;
if (href) {
let matched = href.match(idExpReg);
if (matched) {
href = matched[1];
return <RNSVGTextPath
href={href}
{...this.extractProps({
...props,
x: null,
y: null
})}
{...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'
});
export default TextPath;