mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-09 01:25:01 +00:00
add Use element and add example for it
add Use element and add example for it
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import React, {
|
||||
Component,
|
||||
PropTypes,
|
||||
ART,
|
||||
cloneElement
|
||||
} from 'react-native';
|
||||
let {Group} = ART;
|
||||
import Defs from './Defs';
|
||||
import transformFilter from '../lib/transformFilter';
|
||||
let idReg = /^#(.+)/;
|
||||
class Use extends Component{
|
||||
static displayName = 'Use';
|
||||
static propType = {
|
||||
href: PropTypes.string
|
||||
};
|
||||
|
||||
render() {
|
||||
let href = this.props.href;
|
||||
if (href) {
|
||||
let matched = href.match(idReg);
|
||||
if (matched) {
|
||||
let template = Defs.get(matched[1] + ':' + this.props.svgId);
|
||||
if (template) {
|
||||
let props = {
|
||||
...this.props,
|
||||
href: null
|
||||
};
|
||||
return cloneElement(template, props);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return <Group />;
|
||||
}
|
||||
}
|
||||
|
||||
export default Use;
|
||||
Reference in New Issue
Block a user