Skip to content

feat: calculate width from height #2399

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

Closed
wants to merge 4 commits into from

Conversation

bohdanprog
Copy link
Member

Summary

Closes #2138

We want to calculate width and height based on the aspect ratio defined by the viewBox.

Test Plan

We can easily test my solution when we run the Test2138

Compatibility

OS Implemented
iOS
Android

@bohdanprog bohdanprog self-assigned this Aug 8, 2024
@bohdanprog bohdanprog requested review from WoLewicki and jakex7 August 8, 2024 12:45
@bohdanprog bohdanprog changed the title feat: add test case and try to update Svg element feat: calculate width from height Aug 8, 2024
if (!isNaN(viewBoxWidth) && !isNaN(viewBoxHeight)) {
if (width !== undefined && height === undefined) {
height = isWidthPercentage
? `${(parseFloat(width) * viewBoxHeight) / viewBoxWidth}%`
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the % value is being calculated correctly. For instance, if the screen width is 200 and the height is 600, and we have an SVG with a viewBox proportion of 1 (such as 100/100) and a width set to 50%, the height should match the width. However, in this implementation, the height ends up being 50% of the screen height, which is 300, rather than the expected 100.

@bohdanprog bohdanprog removed the request for review from WoLewicki August 26, 2024 10:25
@bohdanprog bohdanprog marked this pull request as draft August 26, 2024 10:26
@jakex7 jakex7 closed this Oct 31, 2024
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.

SVG doesn't calculate width from height+viewbox (web/native inconsistency)
2 participants