@@ -620,89 +620,15 @@ internal object TextLayoutManager {
620620 )
621621 }
622622
623- // Pre-Android 15: Use existing advance-based logic
624- if (
625- Build .VERSION .SDK_INT < Build .VERSION_CODES .VANILLA_ICE_CREAM ||
626- ! ReactNativeFeatureFlags .fixTextClippingAndroid15useBoundsForWidth()
627- ) {
628- val desiredWidth = ceil(Layout .getDesiredWidth(text, paint)).toInt()
629-
630- val layoutWidth =
631- when (widthYogaMeasureMode) {
632- YogaMeasureMode .EXACTLY -> floor(width).toInt()
633- YogaMeasureMode .AT_MOST -> min(desiredWidth, floor(width).toInt())
634- else -> desiredWidth
635- }
636- return buildLayout(
637- text,
638- layoutWidth,
639- includeFontPadding,
640- textBreakStrategy,
641- hyphenationFrequency,
642- alignment,
643- justificationMode,
644- ellipsizeMode,
645- maxNumberOfLines,
646- paint,
647- )
648- }
649-
650- // Android 15+: Need to account for visual bounds
651- // Step 1: Create unconstrained layout to get visual bounds width
652- val unconstrainedLayout =
653- buildLayout(
654- text,
655- Int .MAX_VALUE / 2 ,
656- includeFontPadding,
657- textBreakStrategy,
658- hyphenationFrequency,
659- alignment,
660- justificationMode,
661- null ,
662- ReactConstants .UNSET ,
663- paint,
664- )
665-
666- // Calculate visual bounds width from unconstrained layout
667- var desiredVisualWidth = 0f
668- for (i in 0 until unconstrainedLayout.lineCount) {
669- val lineWidth = unconstrainedLayout.getLineRight(i) - unconstrainedLayout.getLineLeft(i)
670- desiredVisualWidth = max(desiredVisualWidth, lineWidth)
671- }
623+ val desiredWidth = ceil(Layout .getDesiredWidth(text, paint)).toInt()
672624
673625 val layoutWidth =
674626 when (widthYogaMeasureMode) {
675- YogaMeasureMode .AT_MOST -> min(ceil(desiredVisualWidth).toInt(), floor(width).toInt())
676- else -> ceil(desiredVisualWidth).toInt()
627+ YogaMeasureMode .EXACTLY -> floor(width).toInt()
628+ YogaMeasureMode .AT_MOST -> min(desiredWidth, floor(width).toInt())
629+ else -> desiredWidth
677630 }
678631
679- // Step 2: Create final layout with correct width
680- return buildLayout(
681- text,
682- layoutWidth,
683- includeFontPadding,
684- textBreakStrategy,
685- hyphenationFrequency,
686- alignment,
687- justificationMode,
688- ellipsizeMode,
689- maxNumberOfLines,
690- paint,
691- )
692- }
693-
694- private fun buildLayout (
695- text : Spannable ,
696- layoutWidth : Int ,
697- includeFontPadding : Boolean ,
698- textBreakStrategy : Int ,
699- hyphenationFrequency : Int ,
700- alignment : Layout .Alignment ,
701- justificationMode : Int ,
702- ellipsizeMode : TextUtils .TruncateAt ? ,
703- maxNumberOfLines : Int ,
704- paint : TextPaint ,
705- ): Layout {
706632 val builder =
707633 StaticLayout .Builder .obtain(text, 0 , text.length, paint, layoutWidth)
708634 .setAlignment(alignment)
@@ -723,13 +649,6 @@ internal object TextLayoutManager {
723649 builder.setUseLineSpacingFromFallbacks(true )
724650 }
725651
726- if (
727- Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM &&
728- ReactNativeFeatureFlags .fixTextClippingAndroid15useBoundsForWidth()
729- ) {
730- builder.setUseBoundsForWidth(true )
731- }
732-
733652 return builder.build()
734653 }
735654
0 commit comments