Skip to content

Commit 39b68b1

Browse files
javacheOpen Source Bot
andauthored
Fix style keywords reading back as the wrong unit after a non-integer size (#2056) (#59745) (#59745)
Co-authored-by: Open Source Bot <generatedunixname499836121@meta.com>
1 parent 37bd5e6 commit 39b68b1

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎packages/react-native/ReactCommon/yoga/yoga/style/StyleValueHandle.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ class StyleValueHandle {
7676
// Intentionally leaving out auto as a fast path
7777
enum class Keyword : uint8_t { MaxContent, FitContent, Stretch };
7878

79-
constexpr bool isKeyword(Keyword keyword) const {
80-
return type() == Type::Keyword && value() == static_cast<uint16_t>(keyword);
81-
}
82-
8379
constexpr Type type() const {
8480
return static_cast<Type>(repr_ & kHandleTypeMask);
8581
}

‎packages/react-native/ReactCommon/yoga/yoga/style/StyleValuePool.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ class StyleValuePool {
8989
return StyleSizeLength::undefined();
9090
} else if (handle.isAuto()) {
9191
return StyleSizeLength::ofAuto();
92-
} else if (handle.isKeyword(StyleValueHandle::Keyword::MaxContent)) {
92+
} else if (isKeyword(handle, StyleValueHandle::Keyword::MaxContent)) {
9393
return StyleSizeLength::ofMaxContent();
94-
} else if (handle.isKeyword(StyleValueHandle::Keyword::FitContent)) {
94+
} else if (isKeyword(handle, StyleValueHandle::Keyword::FitContent)) {
9595
return StyleSizeLength::ofFitContent();
96-
} else if (handle.isKeyword(StyleValueHandle::Keyword::Stretch)) {
96+
} else if (isKeyword(handle, StyleValueHandle::Keyword::Stretch)) {
9797
return StyleSizeLength::ofStretch();
9898
} else {
9999
assert(
@@ -132,6 +132,17 @@ class StyleValuePool {
132132
}
133133

134134
private:
135+
bool isKeyword(StyleValueHandle handle, StyleValueHandle::Keyword keyword)
136+
const {
137+
if (handle.type() != StyleValueHandle::Type::Keyword) {
138+
return false;
139+
}
140+
// storeKeyword() keeps an existing pool slot, so the keyword may be there
141+
uint32_t value = handle.isValueIndexed() ? buffer_.get32(handle.value())
142+
: handle.value();
143+
return value == static_cast<uint32_t>(keyword);
144+
}
145+
135146
void storeValue(
136147
StyleValueHandle& handle,
137148
float value,

0 commit comments

Comments
 (0)