Sanjeeviraj M
07/12/2023, 6:24 AMTom De Decker
07/12/2023, 8:04 AM- MyComposable("foo")
- MyComposable("bar")
Compose will "remember" that the first instance of MyComposable receives "foo" as a parameter while the second one receives "bar". If we now add a new item to the list, the first two composable's inputs will not have changed and Compose can (potentially) skip recomposition, requiring only the new item to be composed.
- MyComposable("foo")
- MyComposable("bar")
- MyComposable("baz")
If we now change the order in which these elements appear, however, Compose can no longer easily skip recomposition. Say the user drags and reorders the list as follows:
- MyComposable("foo")
- MyComposable("baz")
- MyComposable("bar")
The first composable's recomposition can be skipped given that its input has not changed, while the second and third no longer have the same input. Had we provided a unique key to each of these composables, however, Compose could still figure out that no new items had been added and that only the order of elements has changed. This in theory allows Compose to skip recomposition for each of these nodes.
About the contentType lambda, I'm not quite sure whether I'm understanding this correctly but from what I can read from the docs it seems that the contentType allows Compose to reuse composables that have scrolled off-screen for new nodes that have the same contentType (similar to how a RecyclerView would work). This allows Compose to only recompose the composable with different parameters instead of having to create it from scratch.
Hope that clears things up (and that I'm not misinforming anyone 😅)Sanjeeviraj M
07/12/2023, 9:36 AMTimo Drick
07/12/2023, 11:32 AM