Skip to content

Commit cf4c9b8

Browse files
committed
chore: respect width & height props on web for SvgImage
1 parent 804cc5c commit cf4c9b8

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/components/icon/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export type IconProps = Omit<ImageProps, 'source'> &
2525
* the icon size
2626
*/
2727
size?: number;
28+
/**
29+
* the icon height
30+
*/
31+
height?: number | string;
32+
/**
33+
* the icon width
34+
*/
35+
width?: number | string;
2836
/**
2937
* whether the icon should flip horizontally on RTL
3038
*/
@@ -53,10 +61,12 @@ const Icon = forwardRef((props: Props, ref: any) => {
5361
assetName,
5462
modifiers,
5563
recorderTag,
64+
width,
65+
height,
5666
...others
5767
} = props;
5868
const {margins} = modifiers;
59-
const iconSize = size ? {width: size, height: size} : undefined;
69+
const iconSize = size ? {width: width ?? size, height: height ?? size} : undefined;
6070
const shouldFlipRTL = supportRTL && Constants.isRTL;
6171

6272
const iconSource = useMemo(() => {

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+
width?: number;
17+
height?: 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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ const itemsToRender: ItemToRender[] = [
5555
size={Button.sizes.large}
5656
iconSource={svgData}
5757
iconStyle={{
58-
width: size,
59-
height: size,
58+
// width: size,
59+
// height: size,
6060
tintColor: '#ffffff'
6161
}}
62+
iconProps={{
63+
width: size,
64+
height: size
65+
}}
6266
onPress={() => {
6367
const newSize = size === Spacings.s4 ? Spacings.s6 : Spacings.s4;
6468
setSize(newSize);

0 commit comments

Comments
 (0)