mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
Add Defs element
Add Defs element
This commit is contained in:
46
elements/Defs.js
Normal file
46
elements/Defs.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import React, {
|
||||
Children,
|
||||
cloneElement,
|
||||
Component,
|
||||
ART
|
||||
} from 'react-native';
|
||||
let {Group} = ART;
|
||||
let map = {};
|
||||
|
||||
// TODO: more details should be handled(different Svg namespace、(remove, add, update) Defs children)
|
||||
class Defs extends Component{
|
||||
static displayName = 'Defs';
|
||||
static get = uid => {
|
||||
return map[uid];
|
||||
};
|
||||
|
||||
static set = (uid, element) => {
|
||||
map[uid] = element;
|
||||
};
|
||||
|
||||
componentWillMount = () => {
|
||||
this.getDefines(this.props.children);
|
||||
};
|
||||
|
||||
componentWillReceiveProps = nextProps => {
|
||||
this.getDefines(nextProps);
|
||||
};
|
||||
|
||||
getDefines = children => {
|
||||
Children.map(children, child => {
|
||||
let {props: {id}} = child;
|
||||
if (id) {
|
||||
console.log(id + ':' + this.props.svgId);
|
||||
map[id + ':' + this.props.svgId] = cloneElement(child, {
|
||||
id: null
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return <Group />;
|
||||
}
|
||||
}
|
||||
|
||||
export default Defs;
|
||||
Reference in New Issue
Block a user