Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/elements/G.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react';
import * as React from 'react';
import { Children } from 'react';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import { extractFont } from '../lib/extract/extractText';
import extractTransform from '../lib/extract/extractTransform';
Expand Down Expand Up @@ -41,11 +42,18 @@ export default class G<P> extends Shape<GProps & P> {
if (hasProps(font)) {
extractedProps.font = font;
}

const childArray = props.children
? Children.map(props.children, (child) =>
React.cloneElement(child, { ...extractedProps })
)
: [];

return (
<RNSVGGroup
ref={(ref) => this.refMethod(ref as (G<P> & NativeMethods) | null)}
{...extractedProps}>
{props.children}
{childArray}
</RNSVGGroup>
);
}
Expand Down
18 changes: 18 additions & 0 deletions src/lib/extract/extractBrush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@ const currentColorBrush = { type: 2 };
const contextFillBrush = { type: 3 };
const contextStrokeBrush = { type: 4 };

function isBrush(color: any): boolean {
const isObject = !!color && typeof color === 'object';
const hasType = () => 'type' in color && typeof color.type === 'number';
const hasBrushRef = () => 'brushRef' in color && typeof color.brushRef === 'string';
const hasPayload = () => 'payload' in color && typeof color.payload === 'number';

return (
isObject &&
hasType() &&
(hasBrushRef() || hasPayload())
);
}

export default function extractBrush(color: ColorValue) {
if (isBrush(color)) {
// If the color comes from the AST it's already a brush
return color;
}

if (color === 'none') {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/extract/extractFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function extractFill(
o.fill =
!fill && typeof fill !== 'number' ? defaultFill : extractBrush(fill);
} else {
inherited.push('fill');
// we want the default value of fill to be black to match the spec
o.fill = defaultFill;
}
Expand Down