Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
import com.bitwarden.ui.platform.base.util.toAnnotatedString

/**
* Returns a [VisualTransformation] that masks text with [mask]. When [staticCharacterCount] is
Comment thread
david-livefront marked this conversation as resolved.
* non-null, the transformed text always contains that number of mask characters.
* non-null and the text is non-empty, the transformed text contains that number of mask
* characters. Blank text is never masked.
*/
@Composable
fun passwordVisualTransformation(
Expand All @@ -30,10 +32,11 @@ private class BitwardenPasswordVisualTransformation(
override fun filter(
text: AnnotatedString,
): TransformedText = TransformedText(
AnnotatedString(
mask.toString().repeat(n = staticCharacterCount ?: text.text.length),
),
object : OffsetMapping {
text = mask
.toString()
.repeat(staticCharacterCount?.takeIf { text.text.isNotEmpty() } ?: text.text.length)
.toAnnotatedString(),
offsetMapping = object : OffsetMapping {
override fun originalToTransformed(
offset: Int,
): Int = staticCharacterCount?.let { offset.coerceAtMost(it) } ?: offset
Expand Down
Loading