add Use element and add example for it

add Use element and add example for it
This commit is contained in:
Horcrux
2016-01-23 19:25:12 +08:00
parent af0995022d
commit 11c211a9a9
12 changed files with 166 additions and 29 deletions
+21 -3
View File
@@ -1,7 +1,9 @@
import React, {
ART,
Component,
PropTypes
PropTypes,
Children,
cloneElement
} from 'react-native';
import _ from 'lodash';
@@ -71,6 +73,8 @@ function extractViewbox({viewbox, width, height, preserveAspectRatio}) {
return false;
}
let id = 0;
class Svg extends Component{
static displayName = 'Svg';
static propType = {
@@ -82,6 +86,20 @@ class Svg extends Component{
preserveAspectRatio: PropTypes.string // preserveAspectRatio only supports 'none' for now
};
constructor() {
super(...arguments);
id++;
this.id = id;
}
getChildren = () => {
return Children.map(this.props.children, child => {
return cloneElement(child, {
svgId: this.id
});
});
};
render() {
let opacity = +this.props.opacity;
let viewbox = extractViewbox(this.props);
@@ -104,7 +122,7 @@ class Svg extends Component{
scaleX={scaleX}
scaleY={scaleY}
>
{this.props.children}
{this.getChildren()}
</Group>}
</Surface>;
}
@@ -118,7 +136,7 @@ class Svg extends Component{
}
]}
>
{this.props.children}
{this.getChildren()}
</Surface>;
}
}