Skip to content

Instantly share code, notes, and snippets.

@Oleur
Created December 13, 2021 18:33
Show Gist options
  • Save Oleur/6ce1b6b85b70fa97bba8bc9d21013a5e to your computer and use it in GitHub Desktop.
Save Oleur/6ce1b6b85b70fa97bba8bc9d21013a5e to your computer and use it in GitHub Desktop.
PasswordVisualTransformation from Jetpack Compose
class PasswordVisualTransformation(val mask: Char = '\u2022') : VisualTransformation {
override fun filter(text: AnnotatedString): TransformedText {
return TransformedText(
text = AnnotatedString(mask.toString().repeat(text.text.length)),
offsetMapping = object : OffsetMapping {
override fun originalToTransformed(offset: Int): Int = offset
override fun transformedToOriginal(offset: Int): Int = offset
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment