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

jannis

12/01/2021, 3:47 PM
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

Zach Klippenstein (he/him) [MOD]

12/01/2021, 6:43 PM
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

jannis

12/02/2021, 9:01 AM
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

Zach Klippenstein (he/him) [MOD]

12/02/2021, 5:31 PM
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

jannis

12/02/2021, 7:17 PM
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

Zach Klippenstein (he/him) [MOD]

12/02/2021, 7:28 PM
Thanks for reporting. Could you post your code and this video on that issue?
j

jannis

12/02/2021, 7:28 PM
I'll push it somewhere and post the link to the repo 👍
Done! 😊
z

Zach Klippenstein (he/him) [MOD]

12/02/2021, 7:47 PM
thanks!
35 Views