raenardev
04/26/2021, 10:09 PMprefix
- to create phone prefix for input field.
Since i needed only visual part, and didn’t need to modify resulting string -> i ended up making it work with VisualTransformation
But what if i need to filter out some characters or modify resulting string in some way?Siyamed
04/26/2021, 10:11 PMSiyamed
04/26/2021, 10:11 PMSiyamed
04/26/2021, 10:19 PMraenardev
04/26/2021, 10:27 PMval fixedPhone = phone.filterNot { it in 'a'..'z' }
I guess i can do that higher up, while forming a state for input, since we don’t store state in it anymore.
But what happens with that - is cursor jumps to next character everytime i input a letter instead of number.
IIRC with InputFilter i didn’t move cursor in such case - pressing invalid character just did nothing.Siyamed
04/26/2021, 10:31 PMSiyamed
04/26/2021, 10:32 PMSiyamed
04/26/2021, 10:34 PMSiyamed
04/26/2021, 10:35 PMSiyamed
04/26/2021, 10:37 PMraenardev
04/26/2021, 10:40 PMInputFilter api didnt look applicable to TextField because of the state hoistingYeah, i agree
putting the cursor back where it should be, becomes an app concernIs there an API for that available now? Say i have made changes to phone string. I would pass modified string to PhoneInput to render. But what about cursor position?
@Composable
fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit) {
BasicTextField(value = phone, onValueChange = onPhoneChanged)
}
Siyamed
04/26/2021, 10:41 PMSiyamed
04/26/2021, 10:41 PMraenardev
04/26/2021, 10:50 PMonValueChange
Seems like i have everything i need for now, will try it out tomorrow.
Thank you 🙂raenardev
04/26/2021, 10:52 PMTextFieldValue.selection
) somewhere in the docs:
https://developer.android.com/jetpack/compose/text#enter-modify-text
I searched for this for a while, before coming to slack.
Again, tnx for your quick response 🙂Siyamed
04/26/2021, 10:53 PM