Add helper method for applying visual transformations to any string (#342)

This commit is contained in:
David Perez 2023-12-06 16:46:04 -06:00 committed by Álison Fernandes
parent 3a42d3e58a
commit ba62eaf6d0

View file

@ -1,9 +1,11 @@
package com.x8bit.bitwarden.ui.platform.base.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.VisualTransformation
import androidx.core.graphics.toColorInt
import java.net.URI
import java.util.Locale
@ -65,6 +67,18 @@ fun String.lowercaseWithCurrentLocal(): String {
return lowercase(LocalContext.current.resources.configuration.locales[0])
}
/**
* A helper method to apply the [visualTransformation] to the given string and and returns the
* transformed [AnnotatedString].
*/
@Composable
fun String.withVisualTransformation(
visualTransformation: VisualTransformation,
): AnnotatedString =
remember(key1 = this) {
visualTransformation.filter(toAnnotatedString()).text
}
/**
* Returns the [String] as an [AnnotatedString].
*/