r

    radzio

    1 year ago
    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)
    Timo Drick

    Timo Drick

    1 year ago
    r

    radzio

    1 year ago
    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.
    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)
            }
        }
    }
    )
    Sean McQuillan [G]

    Sean McQuillan [G]

    1 year ago
    cc @Adam Powell ^
    That works, though I wonder if there's a more efficient way we can recommend
    Adam Powell

    Adam Powell

    1 year ago
    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
    c

    chris

    1 year ago
    In a LazyColumn, how would I scroll to a TextField within a composable that would be hidden by the soft keyboard? The LazyListState doesn't expose the current scroll position.
    Sean McQuillan [G]

    Sean McQuillan [G]

    1 year ago
    tracking down ticket...
    Found it https://issuetracker.google.com/issues/178211874 (apparently it was assigned to me for two days once upon a time 🙂 )
    c

    chris

    1 year ago
    @Sean McQuillan [G] Trying to view it and received
    Access denied
    Sean McQuillan [G]

    Sean McQuillan [G]

    1 year ago
    Ah sorry that's on an internal tracker 😞
    tl;dr It's tracking the larger work required to make textfield focus scroll things