-
Notifications
You must be signed in to change notification settings - Fork 38
/
Svg.js
76 lines (61 loc) · 1.76 KB
/
Svg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @providesModule Svg
* @flow
*/
'use strict';
var React = require('react-native');
var ReactChildren = require('ReactChildren');
var {
View,
PropTypes,
requireNativeComponent,
} = React;
var Svg = React.createClass({
propTypes: {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
},
statics: {
PathSerializer: (path) => {
var { fill, stroke, strokeWidth, strokeMiterLimit, d, transform } = path.props;
return `<path fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" d="${d}" transform="${transform}"/>`
},
LineSerializer: (line) => {
var { x1, x2, y1, y2, style } = path.props;
return `<path fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" d="${d}" transform="${transform}"/>`
}
},
getInitialState() {
return { data: "" }
},
serialize(el) {
return Svg['PathSerializer'](el);
},
stateFromChildren() {
var data = `<svg xmlns="http://www.w3.org/2000/svg" width="${this.props.width}px" height="${this.props.height}px">`;
ReactChildren.forEach(this.props.children, (child) => {
data = data + this.serialize(child);
});
data = data + "</svg>"
return data;
},
render() {
var nativeProps = {
style: this.props.style,
originalWidth: this.props.width,
originalHeight: this.props.height,
forceUpdate: this.props.forceUpdate,
};
if (this.props.source) {
nativeProps.src = this.props.source.uri;
} else if (this.props.data) {
nativeProps.data = this.props.data;
} else {
nativeProps.data = this.stateFromChildren();
}
return <RNSvg {...nativeProps} />
},
});
var RNSvg = requireNativeComponent('RNSvg', null);
Svg.Path = require('./Path');
module.exports = Svg;