From 93b608d130ba6f70d8adeba287e61aa5740a6c5a Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Thu, 12 Sep 2024 14:28:33 -0700 Subject: [PATCH] Make it so that aspect ratio behaves like auto if it is 0 or inf (#46428) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46428 X-link: https://github.com/facebook/yoga/pull/1696 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 Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D62473161 fbshipit-source-id: 6857de819538a7a87ce0a652e99f5a49992921ae --- packages/react-native/ReactCommon/yoga/yoga/style/Style.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index c8cbe56eb94..141540cf5ed 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -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 + pool_.store( + aspectRatio_, + value == 0.0f || std::isinf(value.unwrap()) ? FloatOptional{} : value); } bool horizontalInsetsDefined() const {