-
Notifications
You must be signed in to change notification settings - Fork 734
fix/svg image respect width height props on web #2748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,14 @@ export type IconProps = Omit<ImageProps, 'source'> & | |
* the icon size | ||
*/ | ||
size?: number; | ||
/** | ||
* the icon height | ||
*/ | ||
height?: number | string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About the
To get over this error the user should pass Let's make it only a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adids1221 what string did you use? |
||
/** | ||
* the icon width | ||
*/ | ||
width?: number | string; | ||
/** | ||
* whether the icon should flip horizontally on RTL | ||
*/ | ||
|
@@ -53,10 +61,12 @@ const Icon = forwardRef((props: Props, ref: any) => { | |
assetName, | ||
modifiers, | ||
recorderTag, | ||
width, | ||
height, | ||
...others | ||
} = props; | ||
const {margins} = modifiers; | ||
const iconSize = size ? {width: size, height: size} : undefined; | ||
const iconSize = size ? {width: width ?? size, height: height ?? size} : undefined; | ||
AmitShwarts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const shouldFlipRTL = supportRTL && Constants.isRTL; | ||
|
||
const iconSource = useMemo(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,12 @@ export interface SvgImageProps { | |
tintColor?: string | null; | ||
data: any; // TODO: I thought this should be string | React.ReactNode but it doesn't work properly | ||
style?: object[]; | ||
width?: number | string; | ||
height?: number | string; | ||
} | ||
|
||
function SvgImage(props: SvgImageProps) { | ||
const {data, style = [], tintColor, ...others} = props; | ||
const {data, style = [], tintColor, width, height, ...others} = props; | ||
const [id] = useState(`svg-${new Date().getTime().toString()}`); | ||
const [svgStyleCss, setSvgStyleCss] = useState<string | undefined>(undefined); | ||
|
||
|
@@ -25,13 +27,13 @@ function SvgImage(props: SvgImageProps) { | |
const {postcss, cssjs} = PostCssPackage; | ||
const styleObj: Record<string, any> = StyleSheet.flatten(style); | ||
postcss() | ||
.process(styleObj, {parser: cssjs}) | ||
.process({width, height, ...styleObj}, {parser: cssjs}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add someone that looked at web recently for this part There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.then((style: {css: any}) => { | ||
const svgPathCss = (styleObj?.tintColor) ? `#${id} svg path {fill: ${styleObj?.tintColor}}` : ''; | ||
setSvgStyleCss(`#${id} svg {${style.css}} #${id} {${style.css}} ${svgPathCss}}`); | ||
}); | ||
} | ||
}, [style, id]); | ||
}, [style, id, width, height]); | ||
|
||
if (isSvgUri(data)) { | ||
return <img {...others} src={data.uri} style={StyleSheet.flatten(style)}/>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,10 +55,14 @@ const itemsToRender: ItemToRender[] = [ | |
size={Button.sizes.large} | ||
iconSource={svgData} | ||
iconStyle={{ | ||
width: size, | ||
height: size, | ||
// width: size, | ||
// height: size, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. relevant for the tint. |
||
tintColor: '#ffffff' | ||
}} | ||
iconProps={{ | ||
width: size, | ||
height: size | ||
}} | ||
onPress={() => { | ||
const newSize = size === Spacings.s4 ? Spacings.s6 : Spacings.s4; | ||
setSize(newSize); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also change the type here to
number
.