0

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
        }
    }
vighnesh153
  • 4,354
  • 2
  • 13
  • 27
Tim Schmidt
  • 1,855
  • 3
  • 21
  • 21
  • 1
    Using a Column is not going to be performant if you have a lot of rows inside it. Are you doing some actions on mount/unmount of the component which is why you had to fallback to using `Column`? If yes, I think it would be better for performance, to hoist boolean flags at a parent level and use those flags to determine if you want to do those actions or not. – vighnesh153 Jul 11 '23 at 08:09
  • No there was actually a video in the first row that biz wants to keep playing even when scrolled out of view. Performance isn't too bad since there's only 10 shelves. – Tim Schmidt Jul 11 '23 at 12:22
  • I have scrolling long text issue in `TvLazyColumn` would you mind to help if you know how to fix it? https://stackoverflow.com/questions/76676004/jetpack-compose-tv-is-not-scrollable-and-not-clickable – Arsenius Jul 13 '23 at 04:58

0 Answers0