JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.95k stars 1.16k forks source link

Using spans with LazyVerticalGrid leads to a crash #2102

Open JuBan1 opened 2 years ago

JuBan1 commented 2 years ago

It appears that setting individual spans for items of a LazyVerticalGrid is broken. The following minimal example crashes for me after a few iterations of the while-loop with the message Place was called on a node which was placed already.

@Composable
fun MyComposable() {

    // Quick way of continually updating the item list for the LazyVGrid
    var items by remember { mutableStateOf(emptyList<Int>()) }
    LaunchedEffect(Unit) {
        while(isActive) {
            delay(100)
            items = items + Random.nextInt()
        }
    }

    LazyVerticalGrid(
        columns = GridCells.Fixed(2),
        modifier = Modifier.width(300.dp).height(800.dp)
    ) {
        items(items = items, span = { GridItemSpan(1) } ) { // remove span parameter and it works
            Text(it.toString())
        }
    }
}

Compose-Version: 1.2.0-alpha01-dev686 Platform: desktop (Linux)

JuBan1 commented 2 years ago

I have found a relevant crash report from the Android team: https://issuetracker.google.com/issues/230514914

The issue was solved in the androidx library but as I understand the changes have to merged here to take effect.

Thomas-Vos commented 2 years ago

Same here. You can copy the latest Android source code into your project if you want to work around the issue. It will be fixed once compose-jb is rebased again.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.