perf: optimize handling of font properties in G elements

This commit is contained in:
Mikael Sand
2020-01-18 06:47:49 +02:00
parent 363c1b491f
commit 0fa4177ed7
2 changed files with 16 additions and 14 deletions

View File

@@ -155,13 +155,9 @@ exports[`supports CSS in style element 1`] = `
</svg>"
xmlns="http://www.w3.org/2000/svg"
>
<RNSVGGroup
font={Object {}}
>
<RNSVGGroup>
<RNSVGDefs />
<RNSVGGroup
font={Object {}}
>
<RNSVGGroup>
<RNSVGRect
fill={4294901760}
height={200}
@@ -179,9 +175,7 @@ exports[`supports CSS in style element 1`] = `
y={0}
/>
</RNSVGGroup>
<RNSVGGroup
font={Object {}}
>
<RNSVGGroup>
<RNSVGRect
fill={4294901760}
fillOpacity={0.3}

View File

@@ -24,16 +24,24 @@ export default class G<P> extends Shape<P> {
render() {
const { props } = this;
const prop = propsAndStyles(props);
const extractedProps = extractProps(prop, this);
const font = extractFont(prop);
if (hasProps(font)) {
extractedProps.font = font;
}
return (
<RNSVGGroup
ref={this.refMethod}
{...extractProps(prop, this)}
font={extractFont(prop)}
>
<RNSVGGroup ref={this.refMethod} {...extractedProps}>
{props.children}
</RNSVGGroup>
);
}
}
const hasProps = (obj: {}) => {
for (let _ in obj) {
return true;
}
return false;
};
export const RNSVGGroup = requireNativeComponent('RNSVGGroup');