https://kotlinlang.org logo
#compose
Title
# compose
а

Александр Репин

10/18/2021, 4:27 PM
Hello. What is the best way to decorate each symbol in text field? Each symbol in the text field should be in own composable. It should look like first is a round square, second is a circle and so on
d

dewildte

10/18/2021, 7:37 PM
Can you explain in more detail what you are trying to do?
Does this go beyond the capabilities of the
VisualTransformation
interface?
а

Александр Репин

10/19/2021, 10:00 AM
Hello, Eric, thank you for response. No,
VisualTransformation
does not fully meet my requirements. I need specific view for each symbol in the row
Copy code
Row
 -> Box1
 -> Box2
 -> Box2
The controller of the view should track clicks on keyboard and add new character to the value. The only solution I found is to use multiple
TextField
, one for each
BoxN
. In this case the controller should move focus to another
BoxN's TextField
after value entered. But if do so, then I should somehow set caret position to the end when a
BoxN
clicked. And check that only the last empty
BoxN
is focused. There's another option - use one transparent
TextField
and display values. But it looks like a hack. @dewildte It should look like this
d

dewildte

10/19/2021, 2:25 PM
So upon entering a valid character into the current box the focus needs to shift to the next box correct?
This looks like you are expecting the user to enter some kind of verification PIN. Is that the usecase?
You could set up a
FocusRequester
for each box. As the user enters valid characters you could use the requesters to shift focus to the next box as needed. I suggest ignoring any characters that are invalid. Once the last box contains valid text you can continue on with the rest of the user flow. Deletion can be handled as well by detecting certain key strokes and performing the needed operations in response.
z

Zach Klippenstein (he/him) [MOD]

10/19/2021, 4:39 PM
I think the approaches you described are what other people in this channel have been doing. We’re working on improving the APIs for building this sort of stuff.