Skip to content

Commit 960197a

Browse files
committed
Revert "Fix text clipping on Android 15+ due to useBoundsForWidth change (#54721)"
This reverts commit 19b73cf.
1 parent 8ce7195 commit 960197a

File tree

2 files changed

+4
-89
lines changed

2 files changed

+4
-89
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -542,89 +542,15 @@ internal object TextLayoutManager {
542542
text, paint, layoutWidth, alignment, 1f, 0f, boring, includeFontPadding)
543543
}
544544

545-
// Pre-Android 15: Use existing advance-based logic
546-
if (
547-
Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM ||
548-
!ReactNativeFeatureFlags.fixTextClippingAndroid15useBoundsForWidth()
549-
) {
550-
val desiredWidth = ceil(Layout.getDesiredWidth(text, paint)).toInt()
551-
552-
val layoutWidth =
553-
when (widthYogaMeasureMode) {
554-
YogaMeasureMode.EXACTLY -> floor(width).toInt()
555-
YogaMeasureMode.AT_MOST -> min(desiredWidth, floor(width).toInt())
556-
else -> desiredWidth
557-
}
558-
return buildLayout(
559-
text,
560-
layoutWidth,
561-
includeFontPadding,
562-
textBreakStrategy,
563-
hyphenationFrequency,
564-
alignment,
565-
justificationMode,
566-
ellipsizeMode,
567-
maxNumberOfLines,
568-
paint,
569-
)
570-
}
571-
572-
// Android 15+: Need to account for visual bounds
573-
// Step 1: Create unconstrained layout to get visual bounds width
574-
val unconstrainedLayout =
575-
buildLayout(
576-
text,
577-
Int.MAX_VALUE / 2,
578-
includeFontPadding,
579-
textBreakStrategy,
580-
hyphenationFrequency,
581-
alignment,
582-
justificationMode,
583-
null,
584-
ReactConstants.UNSET,
585-
paint,
586-
)
587-
588-
// Calculate visual bounds width from unconstrained layout
589-
var desiredVisualWidth = 0f
590-
for (i in 0 until unconstrainedLayout.lineCount) {
591-
val lineWidth = unconstrainedLayout.getLineRight(i) - unconstrainedLayout.getLineLeft(i)
592-
desiredVisualWidth = max(desiredVisualWidth, lineWidth)
593-
}
545+
val desiredWidth = ceil(Layout.getDesiredWidth(text, paint)).toInt()
594546

595547
val layoutWidth =
596548
when (widthYogaMeasureMode) {
597-
YogaMeasureMode.AT_MOST -> min(ceil(desiredVisualWidth).toInt(), floor(width).toInt())
598-
else -> ceil(desiredVisualWidth).toInt()
549+
YogaMeasureMode.EXACTLY -> floor(width).toInt()
550+
YogaMeasureMode.AT_MOST -> min(desiredWidth, floor(width).toInt())
551+
else -> desiredWidth
599552
}
600553

601-
// Step 2: Create final layout with correct width
602-
return buildLayout(
603-
text,
604-
layoutWidth,
605-
includeFontPadding,
606-
textBreakStrategy,
607-
hyphenationFrequency,
608-
alignment,
609-
justificationMode,
610-
ellipsizeMode,
611-
maxNumberOfLines,
612-
paint,
613-
)
614-
}
615-
616-
private fun buildLayout(
617-
text: Spannable,
618-
layoutWidth: Int,
619-
includeFontPadding: Boolean,
620-
textBreakStrategy: Int,
621-
hyphenationFrequency: Int,
622-
alignment: Layout.Alignment,
623-
justificationMode: Int,
624-
ellipsizeMode: TextUtils.TruncateAt?,
625-
maxNumberOfLines: Int,
626-
paint: TextPaint,
627-
): Layout {
628554
val builder =
629555
StaticLayout.Builder.obtain(text, 0, text.length, paint, layoutWidth)
630556
.setAlignment(alignment)
@@ -645,13 +571,6 @@ internal object TextLayoutManager {
645571
builder.setUseLineSpacingFromFallbacks(true)
646572
}
647573

648-
if (
649-
Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
650-
ReactNativeFeatureFlags.fixTextClippingAndroid15useBoundsForWidth()
651-
) {
652-
builder.setUseBoundsForWidth(true)
653-
}
654-
655574
return builder.build()
656575
}
657576

packages/rn-tester/js/examples/Text/TextExample.android.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,10 +1408,6 @@ const examples = [
14081408
<RNTesterText style={{fontStyle: 'normal'}}>
14091409
Move fast and be normal
14101410
</RNTesterText>
1411-
<RNTesterText style={{fontStyle: 'italic'}}>
1412-
Move fast and be italic, but just be longer so that you don't fit on
1413-
a single line and make sure text is not truncated.
1414-
</RNTesterText>
14151411
</>
14161412
);
14171413
},

0 commit comments

Comments
 (0)