Skip to content

Commit

Permalink
Make it so that aspect ratio behaves like auto if it is 0 or inf
Browse files Browse the repository at this point in the history
Summary: We do not validate the aspect ratio to ensure it is non zero and non inf in a lot of places. Per the spec, these values should act like auto. There is no auto keyword, but it is the default so I just set the style to a default FloatOptional in this case

Differential Revision: D62473161
  • Loading branch information
joevilches authored and facebook-github-bot committed Sep 10, 2024
1 parent a05f9c6 commit 6958324
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ class YG_EXPORT Style {
return pool_.getNumber(aspectRatio_);
}
void setAspectRatio(FloatOptional value) {
pool_.store(aspectRatio_, value);
// degenerate aspect ratios act as auto.
// see https://drafts.csswg.org/css-sizing-4/#valdef-aspect-ratio-ratio
value == 0.0f || std::isinf(value.unwrap())
? pool_.store(aspectRatio_, FloatOptional())
: pool_.store(aspectRatio_, value);
}

bool horizontalInsetsDefined() const {
Expand Down

0 comments on commit 6958324

Please sign in to comment.