Skip to content
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

Transformation should generate default viewBox property based on SVG width/height #275

Open
dcorbin opened this issue Jun 21, 2023 · 0 comments

Comments

@dcorbin
Copy link

dcorbin commented Jun 21, 2023

Googling around, there are numerous people that want the image to scale up to the full size of the parent view. One such example is this StackOverflow request:
https://stackoverflow.com/questions/61657859/how-to-find-correct-values-for-width-height-and-viewbox-with-react-native-svg/61792447#61792447

They key to the solution provided in that link is viewBox. You need to set the viewBox based on the original documents coordinate system. I found this to be the solution for my usage as well.

The problem is, this requires you to manually code these values, and now your Javascript/Typescript is duplicating information that is in the source .SVG. Edit's the source .SVG may break it.

One possibility is to default viewBox to be '0 0 ${width} ${height}` where width and height come from the SVG file. A less appealing but related solution would be to also export some of the SVG data in a Metadata object:

{ height: 90, width: 90}

I am not an SVG expert, and maybe these properties are not always there and maybe there are some SVGs for which this is insufficient, but I think it would improve things by default for many users.

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

No branches or pull requests

1 participant