Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cards as items are invisible. #2

Open
mainrs opened this issue Jul 2, 2022 · 1 comment
Open

Cards as items are invisible. #2

mainrs opened this issue Jul 2, 2022 · 1 comment

Comments

@mainrs
Copy link

mainrs commented Jul 2, 2022

I am probably missing something. I'd assume items need to have a fixed height/width to make this work. But even setting requiredHeight does not work.

LazyStaggeredGrid(columnCount = 2) {
        notes.forEach { note ->
            item {
                NoteCard(
                    modifier = Modifier.fillMaxWidth(),
                    title = note.embedded.title,
                    content = note.contents[0].value.toString(Charsets.UTF_8))
            }
        }
    }
}

@Composable
private fun NoteCard(
    modifier: Modifier = Modifier,
    title: String,
    content: String? = null,
) {
    Card(modifier = modifier) {
        Text(text = title)
        if (content != null) {
            Text(text = content)
        }
    }
}
@mainrs mainrs changed the title Cards as items have full height and width. Cards as items are invisible. Jul 2, 2022
@mainrs
Copy link
Author

mainrs commented Jul 2, 2022

Looks like your implementation does not get re-composed if the input data changes. I collect my state from a Kotlin Flow using collectAsState(initialState = emptyList()). The lazy grid initializes with the empty list but does not recompose if the list items change. Probably due to the fact that a simple loop is used to iterate over the items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant