Skip to content

Commit

Permalink
refactor: Rename highlighter into highlighted
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 11, 2024
1 parent 297692e commit cefa59e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private val HORIZONTAL_PADDING @Composable get() = with(LocalDensity.current) {
private const val ROTATION_ANGLE_DEGREE = -3f

@Composable
fun HighlighterText(
fun HighlightedText(
templateRes: Int,
argumentRes: Int,
style: TextStyle,
Expand All @@ -57,20 +57,20 @@ fun HighlighterText(
val argument = stringResource(argumentRes)
val text = String.format(template, argument)

val highlighterColor = SwissTransferTheme.colors.highlighterColor
val highlightedColor = SwissTransferTheme.colors.highlightedColor

var highlighterPath by remember { mutableStateOf<Path?>(null) }
var highlightedPath by remember { mutableStateOf<Path?>(null) }

Text(
text = text,
style = style,
onTextLayout = { layoutResult ->
val boundingBoxes = layoutResult.getArgumentBoundingBoxes(text, argument)
highlighterPath = boundingBoxes.transformForHighlighterStyle(verticalPadding, horizontalPadding, angleDegrees)
highlightedPath = boundingBoxes.transformForHighlightedStyle(verticalPadding, horizontalPadding, angleDegrees)
},
modifier = Modifier.drawBehind {
highlighterPath?.let {
drawPath(it, style = Fill, color = highlighterColor)
highlightedPath?.let {
drawPath(it, style = Fill, color = highlightedColor)
}
}
)
Expand All @@ -81,17 +81,17 @@ private fun TextLayoutResult.getArgumentBoundingBoxes(text: String, argument: St
return getBoundingBoxesForRange(start = startIndex, end = startIndex + argument.count())
}

private fun List<Rect>.transformForHighlighterStyle(
private fun List<Rect>.transformForHighlightedStyle(
verticalPadding: Float,
horizontalPadding: Float,
angleDegrees: Float,
): Path = Path().apply {
forEach { boundingBox ->
addPath(boundingBox.transformForHighlighterStyle(verticalPadding, horizontalPadding, angleDegrees))
addPath(boundingBox.transformForHighlightedStyle(verticalPadding, horizontalPadding, angleDegrees))
}
}

private fun Rect.transformForHighlighterStyle(verticalPadding: Float, horizontalPadding: Float, angleDegrees: Float): Path {
private fun Rect.transformForHighlightedStyle(verticalPadding: Float, horizontalPadding: Float, angleDegrees: Float): Path {
return getRotatedRectanglePath(
Rect(
left = left - horizontalPadding,
Expand Down Expand Up @@ -173,7 +173,7 @@ private fun Preview() {
SwissTransferTheme {
Surface {
Box(modifier = Modifier.padding(20.dp)) {
HighlighterText(
HighlightedText(
templateRes = R.string.uploadProgressTitleTemplate,
argumentRes = R.string.uploadProgressTitleArgument,
style = SwissTransferTheme.typography.bodyMedium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.HighlighterText
import com.infomaniak.swisstransfer.ui.components.HighlightedText
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.UploadProgressAdType
import com.infomaniak.swisstransfer.ui.theme.Dimens
import com.infomaniak.swisstransfer.ui.theme.Margin
Expand All @@ -47,7 +46,7 @@ fun ColumnScope.AdHeader(adScreenType: UploadProgressAdType) {
) {
Spacer(modifier = Modifier.height(Margin.Giant))

HighlighterText(
HighlightedText(
templateRes = R.string.uploadProgressTitleTemplate,
argumentRes = R.string.uploadProgressTitleArgument,
style = SwissTransferTheme.typography.bodyMedium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ val CustomDarkColorScheme = CustomColorScheme(
transferFilePreviewOverflow = Color(dark3),
onTransferFilePreviewOverflow = Color(green_main),
transferListStroke = Color(green_main),
highlighterColor = Color(green_dark),
highlightedColor = Color(green_dark),
)
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ val CustomLightColorScheme = CustomColorScheme(
transferFilePreviewOverflow = Color(green_dark),
onTransferFilePreviewOverflow = Color(green_contrast),
transferListStroke = Color(green_dark),
highlighterColor = Color(green_secondary),
highlightedColor = Color(green_secondary),
)
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ data class CustomColorScheme(
val transferFilePreviewOverflow: Color = Color.Unspecified,
val onTransferFilePreviewOverflow: Color = Color.Unspecified,
val transferListStroke: Color = Color.Unspecified,
val highlighterColor: Color = Color.Unspecified,
val highlightedColor: Color = Color.Unspecified,
)

private val Shapes = Shapes(
Expand Down

0 comments on commit cefa59e

Please sign in to comment.