mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-03 15:14:18 +00:00
add Use element and add example for it
add Use element and add example for it
This commit is contained in:
+21
-3
@@ -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>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user