3

I'm creating a program in Jetpack Compose Desktop version 1.0.0-beta5 and I can't figure out how to make Column/LazyColumn scrollable. At the same time, it seems to me that a lot of the classes listed in the documentation for Android are missing and can not work from their examples.

val lazyListState = rememberLazyListState()
val scrollState = rememberScrollState()

LazyColumn(
    state = lazyListState,
    modifier = Modifier.verticalScroll(scrollState)
) {
    items(ArrayList<String>()){ item ->
        Column(modifier = Modifier.padding(8.dp)) {
            Text(item)
        }
    }
}

This code is currently producing an error.

To be precise, the empty list used can be seen in the example, but this is just an adjustment, in fact I draw a lot of items.

5
  • I modified this code to show the List, in fact I draw a number of classes over the List. Commented Oct 29, 2021 at 19:17
  • I removed all the modifiers and remember functions and I was left with this. LazyColumn { items(ArrayList<String>()){ item -> Column(modifier = Modifier.padding(8.dp)) { Text(item) } } }. Unfortunately, scrolling doesn't work. Commented Oct 29, 2021 at 19:33
  • I scrolled through the text and nothing happened. That's why I decided to use a different mouse. It seems to work well with it, so it's probably unsupported hardware. Commented Oct 29, 2021 at 20:29
  • 1
    You can report it to official GitHub including your mouse model and sample project you're using. Commented Oct 29, 2021 at 20:32
  • You could try 'ScrollableTabRow' It is not a perfect solution but might work Commented Nov 2, 2021 at 12:22

2 Answers 2

3

I know this question is very old, but you can take a look at Desktop Compoments

Jetpack compose is for the android framework, Compose desktop is a flavor of Jetpack compose, it uses Skia and Swing under the hood

Sign up to request clarification or add additional context in comments.

Comments

2

you can achive this like this:

val scrollState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
LazyRow(
    state = scrollState,
        modifier = Modifier
        .draggable(
            orientation = Orientation.Horizontal,
            state = rememberDraggableState { delta ->
                coroutineScope.launch {
                    scrollState.scrollBy(-delta)
                }    
            },
        )
) {
    items(100) {
        Text("Test Test Test Test $it")
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.