@@ -13,28 +13,15 @@ import androidx.compose.ui.node.LayoutNode
1313import androidx.compose.ui.text.TextLayoutResult
1414import kotlin.math.roundToInt
1515
16- internal class ComposeTextLayout (
17- internal val layout : TextLayoutResult ,
18- private val hasFillModifier : Boolean ,
19- ) : TextLayout {
16+ internal class ComposeTextLayout (internal val layout : TextLayoutResult ) : TextLayout {
2017 override val lineCount: Int
2118 get() = layout.lineCount
2219
2320 override val dominantTextColor: Int?
2421 get() = null
2522
26- override fun getPrimaryHorizontal (line : Int , offset : Int ): Float {
27- val horizontalPos = layout.getHorizontalPosition(offset, usePrimaryDirection = true )
28- // when there's no `fill` modifier on a Text composable, compose still thinks that there's
29- // one and wrongly calculates horizontal position relative to node's start, not text's start
30- // for some reason. This is only the case for single-line text (multiline works fien).
31- // So we subtract line's left to get the correct position
32- return if (! hasFillModifier && lineCount == 1 ) {
33- horizontalPos - layout.getLineLeft(line)
34- } else {
35- horizontalPos
36- }
37- }
23+ override fun getPrimaryHorizontal (line : Int , offset : Int ) =
24+ layout.getHorizontalPosition(offset, usePrimaryDirection = true )
3825
3926 override fun getEllipsisCount (line : Int ): Int = if (layout.isLineEllipsized(line)) 1 else 0
4027
@@ -92,8 +79,6 @@ internal fun Painter.isMaskable(): Boolean {
9279 ! className.contains(" Brush" )
9380}
9481
95- internal data class TextAttributes (val color : Color ? , val hasFillModifier : Boolean )
96-
9782/* *
9883 * This method is necessary to mask text in Compose.
9984 *
@@ -108,10 +93,9 @@ internal data class TextAttributes(val color: Color?, val hasFillModifier: Boole
10893 *
10994 * We also add special proguard rules to keep the `Text` class names and their `color` member.
11095 */
111- internal fun LayoutNode.findTextAttributes (): TextAttributes {
96+ internal fun LayoutNode.findColor (): Color ? {
11297 val modifierInfos = getModifierInfo()
11398 var color: Color ? = null
114- var hasFillModifier = false
11599 for (index in modifierInfos.indices) {
116100 val modifier = modifierInfos[index].modifier
117101 val modifierClassName = modifier::class .java.name
@@ -127,11 +111,9 @@ internal fun LayoutNode.findTextAttributes(): TextAttributes {
127111 } catch (e: Throwable ) {
128112 null
129113 }
130- } else if (modifierClassName.contains(" Fill" )) {
131- hasFillModifier = true
132114 }
133115 }
134- return TextAttributes ( color, hasFillModifier)
116+ return color
135117}
136118
137119/* *
0 commit comments