I'm using composable BasicTextField:
BasicTextField(
value = viewModel.state.phone,
onValueChange = {
viewModel.onPhoneChanged(if (!it.startsWith("+")) "+$it" else it)
},
visualTransformation = PhoneNumberTransformation(),
)
My viewModel:
fun onPhoneChanged(phone: String) {
state.update {
it.copy(phone = phone)
}
}
As you can see, if the user enters a number as the first character, I force a plus to be added to the zero position.
The plus is added, however in the visual transformation I get an offset equal to 1. For example, I enter 9, in which case +9 should be displayed in the text field, in the visual transformation in the originalToTransformed the offset is equal to 1, although the offset should already be equal to 2 (we must take into account plus). What could be the problem ? help me please