Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

originalToTransformed keeps on looping when when I implemented VisualTransformation for TextField in jetpack compose

I'm trying to implement a custom VisualTransformation for TextField in Jetpack compose. While debugging I found that originalToTransformed of OffsetMapping keeps on calling. Is this an intended behavior or any fix is available for this? I have tested multiple codes even from other GitHub repos, all behave the same.

like image 264
vbp Avatar asked Sep 18 '25 08:09

vbp


1 Answers

I just started implementing one of these for the first time yesterday, and I noticed the same behavior. I'm not 100% certain, but I believe it's because of the blinking cursor. Every time the cursor blinks, it looks like the originalToTransformed function is invoked.

I set a breakpoint on the first line of my implementation and then opened my form in the simulator, and this seems to confirm what I am saying. Once I get past all the initial calls for other reasons, it hits the breakpoint each time the cursor blinks.

I don't know if there is a way to prevent this behavior, but the default seems a bit strange to me that it would continue to calculate the offset each time the cursor blinks, even when the input has not changed. If you happened to have a costly offset calculation, which you probably should not, you might be able to get fancy by tracking that you already computed a transformed offset for the same field value and original offset and skip recomputing the transformed offset.

like image 114
David Hosier Avatar answered Sep 20 '25 23:09

David Hosier