cheonjaeung / gridlayout-compose

Missing non lazy grid layout for Compose Multiplatform.
https://cheonjaeung.github.io/gridlayout-compose
Apache License 2.0
43 stars 3 forks source link

i dont know why, but its laggy, when i putted this gridlayout, and list of views for room, it was so laggy.... #19

Closed sultansse closed 6 months ago

sultansse commented 6 months ago

` data class CategoryDto( val icon: Int, val title: String )

@Composable fun Categories() { val categories = listOf( CategoryDto( icon = R.drawable.img_ai, title = "Ai assistant" ), CategoryDto( icon = R.drawable.img_gmail, title = "Gmail" ), CategoryDto( icon = R.drawable.img_mysdu, title = "MySDU" ), CategoryDto( icon = R.drawable.img_sdukz, title = "Sdu.kz" ), CategoryDto( icon = R.drawable.img_mysdu, title = "Student clubs" ), CategoryDto( icon = R.drawable.img_free_offices, title = "Free Offices" ), CategoryDto( icon = R.drawable.img_moodle, title = "Moodle" ), CategoryDto( icon = R.drawable.img_library, title = "Library" ), )

VerticalGrid(
    columns = SimpleGridCells.Fixed(4),
    modifier = Modifier.padding(8.dp)
) {
    categories.forEach { category ->
        val context = LocalContext.current
        Category(
            category.icon,
            category.title,
            onCategoryClick = { navigateToCategory(context, category.title) },
        )
    }
}

}

@Composable fun Category( icon: Int, title: String, onCategoryClick: () -> Unit, ) { Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, modifier = Modifier .padding(horizontal = 2.dp, vertical = 8.dp) .clickable { onCategoryClick() } ) { Image( painter = painterResource(icon), contentDescription = title, modifier = Modifier .size(56.dp) .shadow(elevation = 4.dp, shape = CircleShape) .clip(CircleShape) ) Text( text = title, textAlign = TextAlign.Center, ) } } ` At first - i want to say thank you for easying our job with this awsome library! buuut here is my code, and i dont know why its laggy. in homescreen i just show in lazyColumn as item this gridlayout and as next item column of notes (just simple notes with room). without this grid - notes work well, i need optimizations, please help

cheonjaeung commented 6 months ago

There are some ways to check what is cause of lag and how to optimize it.

sultansse commented 6 months ago

i tried to make it immutableList, and checked recompositions (used rebugger and layout inspector, but it did not helped, it seems like there is no recompose effect)

here is my code, interesting part is that when i added a lot of note items, and scrolll screen where only notes - it works pretty ok, but top place (where placed only storyly and gridlayout and notes) is very laggy( i even tried to sign app and enabled minifying true debuggle = false and made relase verision, it did not helped

why it can be because of Stories? - becasue when i deleted that part from ui, and leaved only notes and grid - it was still laggy, when only notes - no lag

i am sorry for being newbie, and thank you for your time and attention!

https://pastebin.com/rKbppNGK

cheonjaeung commented 6 months ago

How about to add key to item? For example:

LazyColumn {
    item(
        key = { /* something uniqe key */ }
    ) {
        Caterogories()
    }
}

And if the category list will not changed, try remember it.

val categories = remember { /* init list*/ }

After them, try build app as release build varient.

sultansse commented 6 months ago

i tried this key, but it did not showed me big result, so then i got - each categoryItem had and resource drawable, and i added COIL to load them optimized (rememberAsyncImagePainter) - and it seems like its helped!

so, thank you! For this amazing library, cause i really had troubles with same weighted grid layout, and thank you for your responses and effort!

cheonjaeung commented 6 months ago

Ah, so image loading was the cause of low performance!

Thanks for using my library.

Issue close because question is solved.