Skip to content

chore: infer SVG size from style #2742

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 2 commits into from
Sep 18, 2023

Conversation

AmitShwarts
Copy link
Contributor

@AmitShwarts AmitShwarts commented Sep 11, 2023

Description

Button - support passing iconProps

Changelog

Button - support passing iconProps

Additional info

@AmitShwarts AmitShwarts force-pushed the chore/infer-svg-size-from-style-on-mobile branch from b1c065d to 64046f2 Compare September 11, 2023 11:47
@AmitShwarts AmitShwarts force-pushed the chore/infer-svg-size-from-style-on-mobile branch from 64046f2 to 9920c2b Compare September 11, 2023 11:49
@@ -28,7 +30,12 @@ function SvgImage(props: SvgImageProps) {
if (isSvgUri(data)) {
return <SvgCssUri {...others} uri={data.uri}/>;
} else if (typeof data === 'string') {
return <SvgXml xml={data} {...others}/>;
const flattenStyle = StyleSheet.flatten(props.style) as Record<string, any>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use flatten very rarely, why is this required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to extract the width and height from the provided styles.
do you have suggestion how to do it differently?

Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure its coming with more than one style object ?
if not, and we always have just single style object (and not as array).?
we can remove that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes i'm sure. we can't remove it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please provide the scenario this is used in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for example when using Button with SVG Icon, we're passing iconStyle with width & height.
in this case it's been passed to the SVG component, and without this PR the height and width is not respected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    <Button
      id={id}
      testID={TestIds.buttonElement}
      style={style}
      color={color}
      iconSource={iconSource}
      iconStyle={{width: Spacings.s6, height: Spacings.s6}}
      round
      size={Button.sizes.large}
    />

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed, lets allow passing iconProps to the Button instead, which will allow sending width and height

@M-i-k-e-l M-i-k-e-l merged commit 804cc5c into master Sep 18, 2023
@M-i-k-e-l M-i-k-e-l deleted the chore/infer-svg-size-from-style-on-mobile branch September 18, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants