Hi, I'm playing with Jetpack Compose I've faced on...
# compose
r
Hi, I'm playing with Jetpack Compose I've faced one problem - soft keyboard +
TextField
focus inside scrollable
Column
. I don't know how to scroll
Column
to the selected/focused
TextField
I've creates stackoverflow question too: https://stackoverflow.com/questions/66249829/jetpack-compose-scroll-to-focused-composable-in-column Can someone tell me what is the best approach for this? I don't need/want use LazyColumn (not so many TextFields)
t
r
Unfortunately I didn't help 😞
It seems that I've found working solution, but I'm not sure if it is the best one I've used 
onGloballyPositioned
 and it works.
Copy code
var scrollToPosition = 0.0F

TextField(
   modifier = Modifier
    .focusOrder(countryFocus)
    .onGloballyPositioned { coordinates ->
        scrollToPosition = scrollState.value + coordinates.positionInRoot().y
    }
    .onFocusChanged {
    if (it == FocusState.Active) {
        scope.launch {
            scrollState.smoothScrollTo(scrollToPosition)
        }
    }
}
)
s
cc @Adam Powell ^
That works, though I wonder if there's a more efficient way we can recommend
a
I can't remember where exactly we are with regard to the
requestChildRectOnScreen
equivalents. I'd try to scope the above to just the scrolling container rather than the global root
s
tracking down ticket...
Found it https://issuetracker.google.com/issues/178211874 (apparently it was assigned to me for two days once upon a time 🙂 )
1
3️⃣ 1
🔗 2
0️⃣ 1
4️⃣ 1
😞 1
c
@Sean McQuillan [G] Trying to view it and received
Access denied
s
Ah sorry that's on an internal tracker 😞
tl;dr It's tracking the larger work required to make textfield focus scroll things