Skip to content

Commit

Permalink
refactor: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 11, 2024
1 parent debc550 commit 84ebc08
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.infomaniak.swisstransfer.R
Expand All @@ -42,7 +43,7 @@ import kotlin.math.sin

private val VERTICAL_PADDING @Composable get() = with(LocalDensity.current) { 3.sp.toPx() }
private val HORIZONTAL_PADDING @Composable get() = with(LocalDensity.current) { 10.sp.toPx() }
private const val ROTATION_ANGLE_DEGREE = -3f
private const val ROTATION_ANGLE_DEGREE = -3.0f

@Composable
fun HighlightedText(
Expand Down Expand Up @@ -70,9 +71,9 @@ fun HighlightedText(
},
modifier = Modifier.drawBehind {
highlightedPath?.let {
drawPath(it, style = Fill, color = highlightedColor)
drawPath(path = it, style = Fill, color = highlightedColor)
}
}
},
)
}

Expand Down Expand Up @@ -151,23 +152,24 @@ private fun TextLayoutResult.getBoundingBoxesForRange(start: Int, end: Int): Lis

// `rect.right` is zero for the last space in each line
// Might be an issue: https://issuetracker.google.com/issues/197146630
if (!isLastRect && rect.right == 0f) continue
if (!isLastRect && rect.right == 0.0f) continue

if (firstLineCharRect == null) {
firstLineCharRect = rect
} else if (previousRect != null && (previousRect.bottom != rect.bottom || isLastRect)) {
boundingBoxes.add(
firstLineCharRect.copy(right = previousRect.right)
)
boundingBoxes.add(firstLineCharRect.copy(right = previousRect.right))
firstLineCharRect = rect
}
previousRect = rect
}
return boundingBoxes
}


@PreviewLightAndDark
@Preview(locale = "fr")
@Preview(locale = "de")
@Preview(locale = "es")
@Preview(locale = "it")
@Composable
private fun Preview() {
SwissTransferTheme {
Expand Down

0 comments on commit 84ebc08

Please sign in to comment.