Is there any way to get the position of the Cursor...
# compose
j
Is there any way to get the position of the Cursor within a
TextField
? I know about the
selection
of the
TextFieldValue
. But I need the coordinates. As an alternative: Is there any way to scroll to the current Cursor positon within a scrollable
TextField
or one within a scrollable container?
z
Once you have the character offset of the cursor you can use the
TextLayoutResult
to calculate coordinates.
there any way to scroll to the current Cursor positon within a scrollable 
TextField
 or one within a scrollable container?
I don’t believe so, could you elaborate on what you mean?
j
I have a multiline TextField within a scrollable column which takes approx. 50% height of the screen. When I click on the end of the text the keyboard appears, but the text doesn't scroll to the correct position (and the handle is visible behind other content). I thought this might work as a workaround.
TextLayoutResult
is not available for the
TextField
. Only in the underlying
BasicTextField
or in a
Text
z
Can you post a recording of this behavior? I think I see what you mean but want to be sure. It's probably a bug, so if you just want to file a bug and post a screen recording there that works
j
Yes it's a bug. I think it boils down to this issue: https://issuetracker.google.com/issues/192043120
So no need to create a new one. I just search for ways to build around it 😅
The workaround described doesn't work in my case though
Here is a recording:
Basically: Long Text + height constraint
TextField
+ Keyboard => cursor scroll is missing. If the handle is visible you would see it over the white area at the bottom) Note: I use the Accompanist library (Insets) and an Android 12 Device
z
Thanks for reporting. Could you post your code and this video on that issue?
j
I'll push it somewhere and post the link to the repo 👍
Done! 😊
z
thanks!
188 Views