Skip to content

Width and height props added to Icon, passed only in case of svg icon #2583

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

Merged
merged 6 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion src/components/icon/icon.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
{"name": "assetGroup", "type": "string", "description": "the asset group, default is icons"},
{"name": "tintColor", "type": "string", "description": "The icon tint"},
{"name": "size", "type": "number", "description": "The icon size"},
{"name": "supportRTL", "type": "boolean", "description": "whether the image should flip horizontally on RTL locals"}
{"name": "supportRTL", "type": "boolean", "description": "whether the image should flip horizontally on RTL locals"},
{"name": "width", "type": "string | number", "description": "The icon width, width will be used only in case that the icon is svg image"},
{"name": "height", "type": "string | number;", "description": "The icon height, height will be used only in case that the icon is svg image"}
],
"snippet": [
"<Icon source={{uri: 'https://github.com/wix/react-native-ui-lib/blob/master/demo/src/assets/icons/delete.png'}$1} size={24$2} tintColor={Colors.grey40$3}/>"
Expand Down
9 changes: 9 additions & 0 deletions src/components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ export type IconProps = Omit<ImageProps, 'source'> &
* whether the icon should flip horizontally on RTL
*/
supportRTL?: boolean;
/**
*
* The icon width, width will be used only in case that the icon is svg image.
*/
width?: string | number;
/**
* The icon height, height will be used only in case that the icon is svg image.
*/
height?: string | number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to add the types (which will only work for SVG) and not set width\height from size to the SVG image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since RN deprecated the width and height props from ImageProps I thought we should add them to the component so the user could still pass them.
On the other hand, you are right we can take the size and pass it as width and height.
Should we go on the size solution ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we can achieve the same result with less props it's better, especially if they are only applicable in specific situations.
It'll probably require a little more code, but I doubt it's a lot more code.

source?: ImageProps['source']
};

Expand Down