Skip to content

Commit 10c424b

Browse files
authored
chore: [WEB] SvgImage respect width & height props (#2749)
1 parent 9b61d2f commit 10c424b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/components/icon/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Icon = forwardRef((props: Props, ref: any) => {
7676
/>
7777
);
7878

79-
const renderSvg = () => <SvgImage fsTagName={recorderTag} data={source} {...props} {...iconSize}/>;
79+
const renderSvg = () => <SvgImage fsTagName={recorderTag} data={source} {...iconSize} {...props}/>;
8080

8181
if (typeof source === 'string' && isBase64ImageContent(source) && Constants.isWeb) {
8282
return renderImage();

src/components/svgImage/index.web.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export interface SvgImageProps {
1313
tintColor?: string | null;
1414
data: any; // TODO: I thought this should be string | React.ReactNode but it doesn't work properly
1515
style?: object[];
16+
height?: number;
17+
width?: number;
1618
}
1719

1820
function SvgImage(props: SvgImageProps) {
19-
const {data, style = [], tintColor, ...others} = props;
21+
const {data, style = [], tintColor, width, height, ...others} = props;
2022
const [id] = useState(`svg-${new Date().getTime().toString()}`);
2123
const [svgStyleCss, setSvgStyleCss] = useState<string | undefined>(undefined);
2224

@@ -25,13 +27,13 @@ function SvgImage(props: SvgImageProps) {
2527
const {postcss, cssjs} = PostCssPackage;
2628
const styleObj: Record<string, any> = StyleSheet.flatten(style);
2729
postcss()
28-
.process(styleObj, {parser: cssjs})
30+
.process({width, height, ...styleObj}, {parser: cssjs})
2931
.then((style: {css: any}) => {
3032
const svgPathCss = (styleObj?.tintColor) ? `#${id} svg path {fill: ${styleObj?.tintColor}}` : '';
3133
setSvgStyleCss(`#${id} svg {${style.css}} #${id} {${style.css}} ${svgPathCss}}`);
3234
});
3335
}
34-
}, [style, id]);
36+
}, [style, id, width, height]);
3537

3638
if (isSvgUri(data)) {
3739
return <img {...others} src={data.uri} style={StyleSheet.flatten(style)}/>;

webDemo/src/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ const itemsToRender: ItemToRender[] = [
5555
size={Button.sizes.large}
5656
iconSource={svgData}
5757
iconStyle={{
58-
width: size,
59-
height: size,
6058
tintColor: '#ffffff'
6159
}}
60+
iconProps={{
61+
width: size,
62+
height: size
63+
}}
6264
onPress={() => {
6365
const newSize = size === Spacings.s4 ? Spacings.s6 : Spacings.s4;
6466
setSize(newSize);

0 commit comments

Comments
 (0)