Honza Rössler
Honza Rössler

Reputation: 372

Jetpack Compose Desktop: Scrollable Column/LazyColumn

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.

Upvotes: 3

Views: 4149

Answers (2)

MohammadBaqer
MohammadBaqer

Reputation: 1425

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")
    }
}

Upvotes: 2

Eel
Eel

Reputation: 1449

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

Upvotes: 3

Related Questions