mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 14:05:09 +00:00
优化 Symbol
优化 Symbol
This commit is contained in:
@@ -15,7 +15,7 @@ class SymbolExample extends Component{
|
|||||||
height="150"
|
height="150"
|
||||||
width="110"
|
width="110"
|
||||||
>
|
>
|
||||||
<Symbol id="symbol" viewbox="0 0 150 110">
|
<Symbol id="symbol" viewbox="0 0 150 110" width="100" height="50">
|
||||||
<Circle cx="50" cy="50" r="40" strokeWidth="8" stroke="red" fill="red"/>
|
<Circle cx="50" cy="50" r="40" strokeWidth="8" stroke="red" fill="red"/>
|
||||||
<Circle cx="90" cy="60" r="40" strokeWidth="8" stroke="green" fill="white"/>
|
<Circle cx="90" cy="60" r="40" strokeWidth="8" stroke="green" fill="white"/>
|
||||||
</Symbol>
|
</Symbol>
|
||||||
@@ -24,8 +24,6 @@ class SymbolExample extends Component{
|
|||||||
href="#symbol"
|
href="#symbol"
|
||||||
x="0"
|
x="0"
|
||||||
y="0"
|
y="0"
|
||||||
width="100"
|
|
||||||
height="50"
|
|
||||||
/>
|
/>
|
||||||
<Use
|
<Use
|
||||||
href="#symbol"
|
href="#symbol"
|
||||||
@@ -41,7 +39,6 @@ class SymbolExample extends Component{
|
|||||||
width="50"
|
width="50"
|
||||||
height="25"
|
height="25"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</Svg>;
|
</Svg>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,26 +43,14 @@ class Svg extends Component{
|
|||||||
render() {
|
render() {
|
||||||
let {props} = this;
|
let {props} = this;
|
||||||
let opacity = +props.opacity;
|
let opacity = +props.opacity;
|
||||||
if (props.viewbox) {
|
let content = props.viewbox ? <ViewBox
|
||||||
return <Surface
|
viewbox={props.viewbox}
|
||||||
{...props}
|
preserveAspectRatio={props.preserveAspectRatio}
|
||||||
style={[
|
width={props.width}
|
||||||
props.style,
|
height={props.height}
|
||||||
!isNaN(opacity) && {
|
>
|
||||||
opacity: opacity
|
{this.getChildren()}
|
||||||
}
|
</ViewBox> : this.getChildren();
|
||||||
]}
|
|
||||||
>
|
|
||||||
<ViewBox
|
|
||||||
viewbox={props.viewbox}
|
|
||||||
preserveAspectRatio={props.preserveAspectRatio}
|
|
||||||
width={props.width}
|
|
||||||
height={props.height}
|
|
||||||
>
|
|
||||||
{this.getChildren()}
|
|
||||||
</ViewBox>
|
|
||||||
</Surface>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Surface
|
return <Surface
|
||||||
{...props}
|
{...props}
|
||||||
@@ -73,7 +61,7 @@ class Svg extends Component{
|
|||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{this.getChildren()}
|
{content}
|
||||||
</Surface>;
|
</Surface>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ class Symbol extends Component{
|
|||||||
svgId={props.svgId}
|
svgId={props.svgId}
|
||||||
>
|
>
|
||||||
<ViewBox
|
<ViewBox
|
||||||
|
{...props}
|
||||||
viewbox={props.viewbox}
|
viewbox={props.viewbox}
|
||||||
preserveAspectRatio={props.preserveAspectRatio}
|
preserveAspectRatio={props.preserveAspectRatio}
|
||||||
width={props.width}
|
|
||||||
height={props.height}
|
|
||||||
shouldTransform={true}
|
shouldTransform={true}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import extractViewbox from '../lib/extractViewbox';
|
|||||||
class ViewBox extends Component{
|
class ViewBox extends Component{
|
||||||
static displayName = 'ViewBox';
|
static displayName = 'ViewBox';
|
||||||
static propType = {
|
static propType = {
|
||||||
transform: PropTypes.bool
|
shouldTransform: PropTypes.bool
|
||||||
};
|
};
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
transform: false
|
shouldTransform: false
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -32,12 +32,14 @@ class ViewBox extends Component{
|
|||||||
y = viewbox.y;
|
y = viewbox.y;
|
||||||
}
|
}
|
||||||
return <G
|
return <G
|
||||||
|
{...this.props}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
scaleX={scaleX}
|
scaleX={scaleX}
|
||||||
scaleY={scaleY}
|
scaleY={scaleY}
|
||||||
id={this.props.id}
|
preserveAspectRatio={null}
|
||||||
svgId={this.props.svgId}
|
viewbox={null}
|
||||||
|
preserveAspectRatio={null}
|
||||||
>
|
>
|
||||||
{(!scaleX || !scaleY) ? null : this.props.children}
|
{(!scaleX || !scaleY) ? null : this.props.children}
|
||||||
</G>
|
</G>
|
||||||
|
|||||||
Reference in New Issue
Block a user