Skip to content
Open
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
27 changes: 23 additions & 4 deletions src/elements/Svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export default class Svg extends Shape<SvgProps> {
height,
focusable,
transform,
x,
y,

// Inherited G properties
font,
Expand All @@ -136,6 +138,8 @@ export default class Svg extends Shape<SvgProps> {
}

const props: extractedProps = extracted as extractedProps;
delete (props as Record<string, unknown>).x;
delete (props as Record<string, unknown>).y;
Comment on lines 140 to +142
props.focusable = Boolean(focusable) && focusable !== 'false';
const rootStyles: StyleProp<ViewStyle>[] = [defaultStyle];

Expand Down Expand Up @@ -178,13 +182,29 @@ export default class Svg extends Shape<SvgProps> {
extractResponder(props, props, this as ResponderInstanceProps);

const gStyle = Object.assign({}, StyleSheet.flatten(style));
if (transform) {
if (transform || x != null || y != null) {
if (gStyle.transform) {
props.transform = gStyle.transform;
gStyle.transform = undefined;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
props.transform = extractTransformSvgView(props as any);
const svgTransform = extractTransformSvgView(props as any);
Comment on lines 184 to +191
if (x != null || y != null) {
const translateX = x != null ? parseFloat(String(x)) : 0;
const translateY = y != null ? parseFloat(String(y)) : 0;
const translateTransform = [
{ translateX },
{ translateY },
];
Comment on lines +191 to +198
props.transform = svgTransform
? [
...(Array.isArray(svgTransform) ? svgTransform : [svgTransform]),
...translateTransform,
]
: translateTransform;
} else {
props.transform = svgTransform;
}
}

const RNSVGSvg = Platform.OS === 'android' ? RNSVGSvgAndroid : RNSVGSvgIOS;
Expand All @@ -210,10 +230,9 @@ export default class Svg extends Shape<SvgProps> {
strokeLinecap,
strokeLinejoin,
strokeMiterlimit,
onLayout,
}}
/>
Comment on lines 230 to 234
</RNSVGSvg>
);
}
}
}