Skip to content

Commit b1c065d

Browse files
committed
chore: infer SVG size from style
1 parent 69c2bcb commit b1c065d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/components/svgImage/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import {StyleSheet} from 'react-native';
23
import {isSvg, isSvgUri} from '../../utils/imageUtils';
34
import {SvgPackage} from '../../optionalDependencies';
45

@@ -12,6 +13,7 @@ export interface SvgImageProps {
1213
*/
1314
tintColor?: string | null;
1415
data: any; // TODO: I thought this should be string | React.ReactNode but it doesn't work properly
16+
style?: object[];
1517
}
1618

1719
function SvgImage(props: SvgImageProps) {
@@ -28,7 +30,8 @@ function SvgImage(props: SvgImageProps) {
2830
if (isSvgUri(data)) {
2931
return <SvgCssUri {...others} uri={data.uri}/>;
3032
} else if (typeof data === 'string') {
31-
return <SvgXml xml={data} {...others}/>;
33+
const flattenStyle = StyleSheet.flatten(props.style) as Record<string, any>;
34+
return <SvgXml xml={data} width={flattenStyle?.width} height={flattenStyle?.height} {...others}/>;
3235
} else if (data) {
3336
const File = data; // Must be with capital letter
3437
return <File {...others}/>;

0 commit comments

Comments
 (0)