Hi. I'm trying to get the top offset of cursor in ...
# compose
a
Hi. I'm trying to get the top offset of cursor in a
BasicTextField
. A solution I'm currently using is using the
onTextLayout
callback and from there, accessing
textLayoutResult.getCursorRect(textFieldValue.selection.end).top
. This works perfectly fine, but, It's only re-evaluated during a change in text layout and moving the cursor doesn't trigger that. So a solution I could think of is forcefully trigger
onTextLayout
on each change of cursor; but I don't know how and plus, it's probably inefficient and definitely hacky. Can anyone provide another solution or maybe an idea for triggering
onTextLayout
?
đź‘€ 1
z
Just take what you’re doing and run the calculation inside the
snapshotFlow
function - assuming your
textFieldValue
and
textLayoutResult
are stored in snapshot state objects, that should trigger a recalculation whenever either of them change.