Revert "Fix text clipping on Android 15+ due to useBoundsForWidth change (#54721)"

This reverts commit c931fa81e7.
This commit is contained in:
Christian Falch committed 2026-02-05 16:28:37 +01:00
1 parent 94eada0523
commit 82a0dc08d3
2 files changed
+4 -89

No files matched your search

@@ -620,89 +620,15 @@ internal object TextLayoutManager {
)
}
// Pre-Android 15: Use existing advance-based logic
if (
Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM ||
!ReactNativeFeatureFlags.fixTextClippingAndroid15useBoundsForWidth()
) {
val desiredWidth = ceil(Layout.getDesiredWidth(text, paint)).toInt()
val layoutWidth =
when (widthYogaMeasureMode) {
YogaMeasureMode.EXACTLY -> floor(width).toInt()
YogaMeasureMode.AT_MOST -> min(desiredWidth, floor(width).toInt())
else -> desiredWidth
}
return buildLayout(
text,
layoutWidth,
includeFontPadding,
textBreakStrategy,
hyphenationFrequency,
alignment,
justificationMode,
ellipsizeMode,
maxNumberOfLines,
paint,
)
}
// Android 15+: Need to account for visual bounds
// Step 1: Create unconstrained layout to get visual bounds width
val unconstrainedLayout =
buildLayout(
text,
Int.MAX_VALUE / 2,
includeFontPadding,
textBreakStrategy,
hyphenationFrequency,
alignment,
justificationMode,
null,
ReactConstants.UNSET,
paint,
)
// Calculate visual bounds width from unconstrained layout
var desiredVisualWidth = 0f
for (i in 0 until unconstrainedLayout.lineCount) {
val lineWidth = unconstrainedLayout.getLineRight(i) - unconstrainedLayout.getLineLeft(i)
desiredVisualWidth = max(desiredVisualWidth, lineWidth)
}
val desiredWidth = ceil(Layout.getDesiredWidth(text, paint)).toInt()
val layoutWidth =
when (widthYogaMeasureMode) {
YogaMeasureMode.AT_MOST -> min(ceil(desiredVisualWidth).toInt(), floor(width).toInt())
else -> ceil(desiredVisualWidth).toInt()
YogaMeasureMode.EXACTLY -> floor(width).toInt()
YogaMeasureMode.AT_MOST -> min(desiredWidth, floor(width).toInt())
else -> desiredWidth
}
// Step 2: Create final layout with correct width
return buildLayout(
text,
layoutWidth,
includeFontPadding,
textBreakStrategy,
hyphenationFrequency,
alignment,
justificationMode,
ellipsizeMode,
maxNumberOfLines,
paint,
)
}
private fun buildLayout(
text: Spannable,
layoutWidth: Int,
includeFontPadding: Boolean,
textBreakStrategy: Int,
hyphenationFrequency: Int,
alignment: Layout.Alignment,
justificationMode: Int,
ellipsizeMode: TextUtils.TruncateAt?,
maxNumberOfLines: Int,
paint: TextPaint,
): Layout {
val builder =
StaticLayout.Builder.obtain(text, 0, text.length, paint, layoutWidth)
.setAlignment(alignment)
@@ -723,13 +649,6 @@ internal object TextLayoutManager {
builder.setUseLineSpacingFromFallbacks(true)
}
if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
ReactNativeFeatureFlags.fixTextClippingAndroid15useBoundsForWidth()
) {
builder.setUseBoundsForWidth(true)
}
return builder.build()
}
@@ -1408,10 +1408,6 @@ const examples = [
<RNTesterText style={{fontStyle: 'normal'}}>
Move fast and be normal
</RNTesterText>
<RNTesterText style={{fontStyle: 'italic'}}>
Move fast and be italic, but just be longer so that you don't fit on
a single line and make sure text is not truncated.
</RNTesterText>
</>
);
},