0

This is a modification of this question. I have an isometric grid of images and curious - is it possible to scroll it in free ways (diagonals included). Currently I have this code and it's possible to scroll 2D:

val scrollStateHorizontal = rememberScrollState()
val scrollStateVertical = rememberScrollState()

Box(
    modifier = Modifier
        .horizontalScroll(scrollStateHorizontal)
        .verticalScroll(scrollStateVertical)
) {
    for (i in 0..8) {
        for (j in 0..7) {
            val start = (y % 2 * 0.5 + x) * width
            val top = i * height * 0.5
            Image(modifier = Modifier.padding(start = start.dp, top = top.dp), painter = ...)                
        }
    }
}

What is interesting:

  1. Can I scroll diagonally?
  2. How can I optimize it (memory consumption, etc.)? Maybe I should use LazyHorizontalGrid including LazyVerticalGrid/LazyColumn/LazyRow?

It seems, LazyHorizontalGrid can't be modified simply adding Modifier.verticalScroll. And it has a lag for first few seconds of scrolling (maybe for caching items) while simple Box scrolling acts smoothly from the start.

Psijic
  • 743
  • 7
  • 20

1 Answers1

0

As of now, there's no official support for this, as far as I know. The only way you could implement this as of the current stable, is by using LazyLayout Composable, or by modifying the verticalScroll (or horizontal) Modifiers. Read here. It is a recent addition to the APIs so the documentation is very scarce. You'll have to look it up on the web for sample implementations.

"Read here"

Richard Onslow Roper
  • 5,477
  • 2
  • 11
  • 42
  • Thanks. You missed a link with "Read here". Maybe it's something like https://www.raywenderlich.com/34398400-lazy-layouts-in-jetpack-compose. Is `LazyLayout` good for memory optimizations? – Psijic Sep 06 '22 at 08:02
  • `LazyLayout` is DESIGNED for memory optimisation, and NO, it is nothing like the link you referred to. If I mean to say Lazy Layouts, I wouldn't enclose it in a codeblock, like I did while saying `LazyLayout`. – Richard Onslow Roper Sep 06 '22 at 13:03