Is it expected Behavior to recompose the items of ...
# compose
s
Is it expected Behavior to recompose the items of LazyColumn on each scroll event ? I was try to log the composition count
Copy code
LazyColumn(
    state = scrollState,
    modifier = Modifier.fillMaxSize()
) {
    item {
        LogCompositions("CompetitionDetailsScreenNew header")
         //Some item
     }
}
a
now, only the new items should be composed when you scroll to them. could you please show more code, more specifically how else do you use scrollState
s
@Andrey Kulikov I'm using LazyColumn like this https://gist.github.com/shakil807g/98c68f81b91d464d469aa8f7002ba8dd item is calling continuously as I scroll, which I guess is the main cause of frame skips. https://gist.github.com/shakil807g/98c68f81b91d464d469aa8f7002ba8dd#file-competitiondetailsscreennew-kt-L36
a
could you please move
collapseFraction
calculation right where it is used, inside
graphicsLayer { .. here .. }
in this case on every
scrollState.firstVisibleItemScrollOffset
update (every scroll) instead of doing recomposition we will only need to update a params on graphics layer, which is very cheap
if in future you will anyway need to recompose when something like this changes you can all least make it recompose less often with trick like this: instead of
Copy code
val collapseFraction =
    (scrollState.firstVisibleItemScrollOffset / collapseRange).coerceIn(0f, 1f)
you do:
Copy code
val collapseFraction = remember(collapseRange) {
    derivedStateOf { (scrollState.firstVisibleItemScrollOffset / collapseRange).coerceIn(0f, 1f) }
}
and now when you use
collapseFraction.value
this value is only recomposed when the resulting float fraction changes.
s
Thanks, i updated my code, but it seems item are recompose only when they are become visible again after scrolling. Performance is still an issue.
a
do you mean items are composed only when the new item became visible? it is expected behaviour. and yes, there are some performance to be made on our side in next releases as well