Skip to content

Commit

Permalink
perf: optimize handling of font properties in G elements
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Jan 18, 2020
1 parent 363c1b4 commit 0fa4177
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
12 changes: 3 additions & 9 deletions __tests__/__snapshots__/css.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -179,9 +175,7 @@ exports[`supports CSS in style element 1`] = `
y={0}
/>
</RNSVGGroup>
<RNSVGGroup
font={Object {}}
>
<RNSVGGroup>
<RNSVGRect
fill={4294901760}
fillOpacity={0.3}
Expand Down
18 changes: 13 additions & 5 deletions src/elements/G.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 0fa4177

Please sign in to comment.