Skip to content

Commit 537d2a6

Browse files
Hector-Zhuangmeta-codesync[bot]
authored andcommitted
fix(ios): force zero width for empty Text component (#55472)
Summary: This PR fixes a layout regression in iO where empty <Text /> components render with a non-zero width. The Motivation: In commit(9fe20d4), the logic to add a placeholder "I" to empty strings was moved from ShadowNode to the platform-specific TextLayoutManager. While the "I" placeholder provides the correct height, the measurement result also includes the width of the "I" character. This causes empty components to take up horizontal space. ## Changelog: [IOS] [FIXED] - Force zero width for empty Text components in Fabric to prevent ghost layout artifacts. Pull Request resolved: #55472 Test Plan: Render a component with an empty string and a background color: ``` <Text style={{ backgroundColor: 'red' }} /> ``` Before: A small red vertical sliver (the width of "I") is visible. After: The component is invisible (0 width) ## Related issue: #55468 Reviewed By: cipolleschi Differential Revision: D94011915 Pulled By: NickGerleman fbshipit-source-id: 8408dc43f06bd67e5938004148a4c9ebd3939864
1 parent 117f3c9 commit 537d2a6

File tree

1 file changed

+10
-1
lines changed
  • packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager

1 file changed

+10
-1
lines changed

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
switch (attributedStringBox.getMode()) {
3939
case AttributedStringBox::Mode::Value: {
40-
auto attributedString = ensurePlaceholderIfEmpty_DO_NOT_USE(attributedStringBox.getValue());
40+
auto originalAtributedString = attributedStringBox.getValue();
41+
auto attributedString = ensurePlaceholderIfEmpty_DO_NOT_USE(originalAtributedString);
4142

4243
measurement = textMeasureCache_.get(
4344
{.attributedString = attributedString,
@@ -54,6 +55,14 @@
5455
layoutContext:layoutContext
5556
layoutConstraints:layoutConstraints];
5657

58+
// TODO(D63303709): We compensate for the placeholder character
59+
// being used to represent empty string. iOS TextLayoutManager
60+
// should instead measure using `baseTextAttributes` of the
61+
// `AttributedString`.
62+
if (originalAtributedString.isEmpty()) {
63+
measurement.size.width = 0;
64+
}
65+
5766
if (telemetry) {
5867
telemetry->didMeasureText();
5968
}

0 commit comments

Comments
 (0)