-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
feat: Add string support for aspectRatio #34629
feat: Add string support for aspectRatio #34629
Conversation
Base commit: 8cdc9e7 |
Base commit: 8cdc9e7 |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
} | ||
|
||
const match = new RegExp( | ||
/(^\s*[+]?\d+([.]\d+)?\s*$)|(^\s*([+]?\d+([.]\d+)?)\s*\/\s*([+]?\d+([.]\d+)?)\s*$)/, |
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.
Quoting @jacdebug:
This regex is not easily maintainable also fails on values like auto 4 / 3, can we follow spec and check simple splitting by space will work?
https://css-tricks.com/almanac/properties/a/aspect-ratio/#aa-values
Also this transforms will add up and have some runtime cost, we should do static transforms at build time using babel
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.
@cipolleschi and @jacdebug react native does not really support auto
as a value for aspectRatio, any ideas on how we should handle that? Should we default auto
to some specific value?
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.
The main problem I can think of about using splitting by space is that it wouldn't be able to handle cases like '4/3'
, '4 /3'
or '4/ 3'
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.
auto
can just do nothing since it's the default. And because there is no concept of a "replaced element" in RN, auto <ratio>
should probably not be allowed. You can split on auto
(to print warning), split on /
, trim white space if needed, and parse the floats
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.
Updated
2e322ce
to
60895da
Compare
return aspectRatio; | ||
} | ||
|
||
const matches = aspectRatio.split('/').map(s => s.trim()); |
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.
It actually looks like we don't need to trim, as Number apparently does that internally
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi @gabrieldonadel, thanks for all your work with these PRs. We recently started to maintain the TypeScript types and it looks like that this PR touches the Flow types in the |
60895da
to
ccf2db5
Compare
Hi @cipolleschi, thanks for reviewing this, I've just pushed a commit updating TS types |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
ccf2db5
to
e8177d4
Compare
Hi @gabrieldonadel. We are almost there, many thanks for your patience. |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @gabrieldonadel in 14c91cd. When will my fix make it into a release? | Upcoming Releases |
Summary: This updates `aspectRatio` to support string values and ratio formats, i.e., `'16 / 9'`, thus aligning it with the [CSS Box Sizing Module Level 4](https://drafts.csswg.org/css-sizing-4/#aspect-ratio) specification as requested on facebook#34425. This also adds unit tests to the `processAspectRatio` function ensuring the style processing works as expected. ## Changelog [General] [Added] - Add string support for aspectRatio Pull Request resolved: facebook#34629 Test Plan: This can be tested either through `processAspectRatio-tests` or by using the following code: ```js <View style={{ backgroundColor: '#527FE4', aspectRatio: '16 / 9', }} /> ``` https://user-images.githubusercontent.com/11707729/189029904-da1dc0a6-85de-46aa-8ec2-3567802c8719.mov Reviewed By: jacdebug Differential Revision: D39423304 Pulled By: cipolleschi fbshipit-source-id: d323de93d6524e411e7ab9943335a8ca323b6e61
Summary
This updates
aspectRatio
to support string values and ratio formats, i.e.,'16 / 9'
, thus aligning it with the CSS Box Sizing Module Level 4 specification as requested on #34425. This also adds unit tests to theprocessAspectRatio
function ensuring the style processing works as expected.Changelog
[General] [Added] - Add string support for aspectRatio
Test Plan
This can be tested either through
processAspectRatio-tests
or by using the following code:Screen.Recording.2022-09-08.at.00.47.42.mov