@@ -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
0 commit comments