Skip to content

Commit 98d07b3

Browse files
Fix text layout cache key for maxFontSizeMultiplier (#56960)
Summary: Text layout measurement cache keys currently consider `fontSizeMultiplier` and `allowFontScaling`, but omit `maxFontSizeMultiplier`. When that cap changes, Fabric can reuse a stale measurement even though the effective scaled font size may change. This adds `maxFontSizeMultiplier` to the layout-wise text attribute equality and hash helpers, and covers the cache-key behavior with focused C++ tests. Fixes #56921. ## Changelog: [GENERAL] [FIXED] - Include `maxFontSizeMultiplier` in Fabric text layout cache keys. Pull Request resolved: #56960 Test Plan: - `npx --yes clang-format --dry-run --Werror packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp` - `git diff --check` I could not run the native gtest target locally from this sparse checkout; the patch adds focused coverage in the existing `TextLayoutManagerTest.cpp` file. Reviewed By: sammy-SC Differential Revision: D106362229 Pulled By: javache fbshipit-source-id: 8977afe60b497344713af437eec48d5340eaed6c
1 parent 5fce2de commit 98d07b3

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ inline bool areTextAttributesEquivalentLayoutWise(const TextAttributes &lhs, con
130130
rhs.dynamicTypeRamp,
131131
rhs.alignment) &&
132132
floatEquality(lhs.fontSize, rhs.fontSize) && floatEquality(lhs.fontSizeMultiplier, rhs.fontSizeMultiplier) &&
133-
floatEquality(lhs.letterSpacing, rhs.letterSpacing) && floatEquality(lhs.lineHeight, rhs.lineHeight);
133+
floatEquality(lhs.letterSpacing, rhs.letterSpacing) && floatEquality(lhs.lineHeight, rhs.lineHeight) &&
134+
floatEquality(lhs.maxFontSizeMultiplier, rhs.maxFontSizeMultiplier);
134135
}
135136

136137
inline size_t textAttributesHashLayoutWise(const TextAttributes &textAttributes)
@@ -145,6 +146,7 @@ inline size_t textAttributesHashLayoutWise(const TextAttributes &textAttributes)
145146
textAttributes.fontStyle,
146147
textAttributes.fontVariant,
147148
textAttributes.allowFontScaling,
149+
textAttributes.maxFontSizeMultiplier,
148150
textAttributes.dynamicTypeRamp,
149151
textAttributes.letterSpacing,
150152
textAttributes.lineHeight,

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,42 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include <memory>
9-
108
#include <gtest/gtest.h>
119

12-
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
10+
#include <react/renderer/textlayoutmanager/TextMeasureCache.h>
1311

1412
using namespace facebook::react;
1513

16-
TEST(TextLayoutManagerTest, testSomething) {
17-
// TODO:
14+
TEST(TextLayoutManagerTest, defaultTextAttributesAreLayoutEquivalent) {
15+
TextAttributes lhs;
16+
TextAttributes rhs;
17+
18+
EXPECT_TRUE(areTextAttributesEquivalentLayoutWise(lhs, rhs));
19+
EXPECT_EQ(
20+
textAttributesHashLayoutWise(lhs), textAttributesHashLayoutWise(rhs));
21+
}
22+
23+
TEST(TextLayoutManagerTest, maxFontSizeMultiplierAffectsLayoutCacheEquality) {
24+
TextAttributes lhs;
25+
TextAttributes rhs;
26+
27+
lhs.fontSize = rhs.fontSize = 16;
28+
lhs.fontSizeMultiplier = rhs.fontSizeMultiplier = 2;
29+
lhs.maxFontSizeMultiplier = 1;
30+
rhs.maxFontSizeMultiplier = 2;
31+
32+
EXPECT_FALSE(areTextAttributesEquivalentLayoutWise(lhs, rhs));
33+
}
34+
35+
TEST(TextLayoutManagerTest, maxFontSizeMultiplierAffectsLayoutCacheHash) {
36+
TextAttributes lhs;
37+
TextAttributes rhs;
38+
39+
lhs.fontSize = rhs.fontSize = 16;
40+
lhs.fontSizeMultiplier = rhs.fontSizeMultiplier = 2;
41+
lhs.maxFontSizeMultiplier = 1;
42+
rhs.maxFontSizeMultiplier = 2;
43+
44+
EXPECT_NE(
45+
textAttributesHashLayoutWise(lhs), textAttributesHashLayoutWise(rhs));
1846
}

0 commit comments

Comments
 (0)