Bagadeshkumar R
04/17/2023, 6:33 PMval list: List<SomeData> by somethingFlow.collectAsState() // somethingFlow is StateFlow<List<SomeData>>
LazyColum {
items(list, key = { it.id }) {
SomeDataDetail(…) {
vm.updateBookMark(true)
}
}
}
So when vm.updateBookMark
is done somethingFlow
gets new data (It is StateFlow as mentioned) . If SomeData.isBookMark
is changed in any item this will cause the StateFlow to return emit the new List which will cause the entire visible items to recompose. I have checked the nowInAndroid app, Visible Items List are recomposed
Question:
Is recomposing all the visible items is the best practise? If not what are the alternatives?
My case is small items in the List like todoList enabled item or not.(I really don't want the other items in the list to recompose just because the partiular item's state is changed)vide
04/18/2023, 1:15 AMSomeDataDetail
is skippable, only the list items whose parameters have changed will be recomposed. See https://developer.android.com/jetpack/compose/lifecycle#skipping
If a composable is already in the Composition, it can skip recomposition if all the inputs are stable and haven't changed.
Bagadeshkumar R
04/18/2023, 5:44 AMrestartable skippable scheme
So it should have skipped but It isn't.vide
04/18/2023, 5:46 AMBagadeshkumar R
04/18/2023, 5:48 AMBagadeshkumar R
04/18/2023, 6:17 AMvide
04/18/2023, 6:25 AMvide
04/18/2023, 6:26 AMBagadeshkumar R
04/18/2023, 6:27 AMinline fun <T> LazyListScope.items(
items: List<T>,
noinline key: ((item: T) -> Any)? = null,
noinline contentType: (item: T) -> Any? = { null },
crossinline itemContent: @Composable LazyItemScope.(item: T) -> Unit
)
I was expecting itemContent to be never called for T that did not change.vide
04/18/2023, 6:28 AMvide
04/18/2023, 6:45 AMitems
and itemContent
are inlined to the parent, LazyColumn
Bagadeshkumar R
04/18/2023, 6:47 AMvide
04/18/2023, 6:48 AMFor every non-inline composable function that returns, the Compose compiler generates code that wraps the function’s body in a recompose scope. When a recompose scope is invalidated, the compose runtime will ensure the (entire) function body gets recomposed (reexecuted) before the next frame. Functions are a natural delimiter for re-executable chunks of code, because they already have well-defined entry and exit points.Unit
`Foo`’s body, `Button`’s body, the content lambda we pass to, `Text`’s body, all get their own recompose scopes.Button
What about inline functions and functions that return a value?
Inline functions are inline - their bodies are effectively copied into their caller, so they share their caller’s recompose scope.
Functions that have a non-unit return value don’t get their own scopes because they can’t be re-executed without also re-executing their caller, so their caller can “see” the new return value computed by the function.
Bagadeshkumar R
04/18/2023, 6:56 AMvide
04/18/2023, 7:11 AM