dimsuz
07/24/2023, 12:40 PMLazyColumn {
item {
if (someState.value) { ListItem(...) }
}
}
and this
LazyColumn {
if (someState.value) {
item {
ListItem(...)
}
}
}
Any performance considerations in either case? Which is better?Stylianos Gakis
07/24/2023, 12:44 PMkey
of the item {}
be for your item on #1 if the item does not exist?dimsuz
07/24/2023, 12:53 PMStylianos Gakis
07/24/2023, 12:57 PMdimsuz
07/24/2023, 1:14 PMAdvitiay Anand
07/24/2023, 2:14 PMCasey Brooks
07/24/2023, 2:37 PMcontent
lambda of LazyColumn
is NOT @Composable
. I’m pretty sure this means that in the case of #2, if the someState.value
value changes the entire LazyColumn
will be recomposed, not just the wrapped item.
If you have individual items each with their own visibility conditions, I think you should keep that as a regular Column
. I also suspect that having individual items with different visibility means their content is also going to be different, so the underlying views won’t really be recycled like they would if you’re actually rendering a List
of items, so the perfomance gains of being lazy might not cover the overhead of recreating those views as it’s scrolledMR3Y
07/24/2023, 2:48 PMdimsuz
07/24/2023, 2:49 PMso the perfomance gains of being lazy might not cover the overhead of recreating those views as it’s scrolledSwitching to Column is not always possible, consider this usecase: A screen with 3 sections, first two are static, but optional, and last "section" is a list of 1000 items. And all 3 must be scrolled together, when they are present. In this case the most natural solution is to use LazyColumn
dimsuz
07/24/2023, 2:53 PMitem
too. It will suggest replacing this (in absence of other layout side-effects)
Column {
if (condition) {
Text()
}
}
with this
if (condition) {
Column {
Text()
}
}
(item
case falls in this category)
Will be adding it to our detekt-rules-compose rule set.Abhimanyu
07/24/2023, 3:00 PMmyanmarking
07/24/2023, 3:33 PMdimsuz
07/24/2023, 4:40 PMAndrey Kulikov
07/24/2023, 5:25 PMdimsuz
07/24/2023, 10:11 PMmyanmarking
07/25/2023, 8:17 AMdimsuz
07/25/2023, 11:14 AMdimsuz
07/25/2023, 11:16 AMdimsuz
07/25/2023, 11:17 AMandylamax
07/27/2023, 7:51 AMstatic data
?? making them eligible for residence in Viewmodel??dimsuz
07/27/2023, 11:14 AMandylamax
07/27/2023, 1:40 PMdimsuz
07/27/2023, 4:45 PM