Does anyone knows how to properly do a Password OutputTransformation to use with a BasicTextField?
I am doing like this:
var exibirSenha by remember { mutableStateOf(false) }
BasicTextField (
modifier = Modifier
.fillMaxWidth()
.onFocusChanged { focusState ->
loginUIState.value.setSenhaInputFocus(focusState.hasFocus)
},
state = senhaState,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done
),
onKeyboardAction = { loginViewModel?.login() },
outputTransformation = if (!exibirSenha) {
SenhaOutputTransformation()
} else {
null
},
leftIcon = Icons.Outlined.Lock,
rightIcon = if (exibirSenha) Icons.Outlined.VisibilityOff else Icons.Outlined.Visibility,
onRightIconClick = {
exibirSenha = !exibirSenha
}
)
And, my SenhaOutputTransformation is like thins:
@Stable
class SenhaOutputTransformation : OutputTransformation {
companion object {
private val tag = SenhaOutputTransformation::class.simpleName
private const val MASCARA_INTERNA = 'u2022'
}
override fun TextFieldBuffer.transformOutput() {
val maskedText = AnnotatedString(MASCARA_INTERNA.toString().repeat(asCharSequence().length))
replace(0, length, maskedText)
}
}
But, when i toogle between visible and back to invisible, when i press backspace all text is cleared!