Make Column scroll item farther into view

428 Views Asked by At

I have an app with a pretty standard TV layout with a list of video shelves. I implemented it as a TvLazyColumn with each shelf being a TvLazyRow of items. Everything worked fine.

Due to business requirements, I had to change the parent composable to from a TvLazyColumn to a regular Column (there was a cell that I didn't want getting unloaded). Ever since then, when I scroll down in the parent column, the currently selected item is at the very bottom of the visible part of the column. Is there an easy way to get the Column to scroll the currently selected item farther up in the viewport?

I managed the pretty big hack below which just, when a scroll occurs, scroll it a little farther. The downside to that is there's a noticeable stutter when it scrolls, briefly stops, then scrolls again.

    var lastScrollValue by remember { mutableStateOf(0) }

    // hack to scroll selected row farther into view
    LaunchedEffect(scrollState.value) {
        if (!scrollState.isScrollInProgress && scrollState.value > lastScrollValue) {
            lastScrollValue = scrollState.value + 100
            scrollState.scrollTo(lastScrollValue)
        } else {
            lastScrollValue = scrollState.value
        }
    }
0

There are 0 best solutions below