FantasyPremierLeague icon indicating copy to clipboard operation
FantasyPremierLeague copied to clipboard

Recomposition happens multiple time

Open Drjacky opened this issue 4 years ago • 4 comments

PlayerDetailsScreen composable has been called multiple times; Thus, https://github.com/joreilly/FantasyPremierLeague/blob/03e841ea3ae3e8be0fc4c2781f3b5f77d6d48bff/app/src/main/java/dev/johnoreilly/fantasypremierleague/MainActivity.kt#L83
get called multiple times. Is that okay? Is there a way to prevent these multiple recompositions?

Drjacky avatar Oct 08 '21 15:10 Drjacky

Are you seeing particular thing triggering that? In general any change of state that the composable uses will trigger recomposition so that at least is expected if/when it happens.

joreilly avatar Oct 08 '21 15:10 joreilly

How to detect who is causing recomposition? Cause breakpoint on https://github.com/joreilly/FantasyPremierLeague/blob/03e841ea3ae3e8be0fc4c2781f3b5f77d6d48bff/app/src/main/java/dev/johnoreilly/fantasypremierleague/MainActivity.kt#L73 is triggered once!

Drjacky avatar Oct 08 '21 16:10 Drjacky

Okay, onPlayerSelected triggered multiple times during all of the calls on https://github.com/joreilly/FantasyPremierLeague/blob/03e841ea3ae3e8be0fc4c2781f3b5f77d6d48bff/app/src/main/java/dev/johnoreilly/fantasypremierleague/presentation/players/PlayersListView.kt#L61


Right now, you have this local https://github.com/joreilly/FantasyPremierLeague/blob/03e841ea3ae3e8be0fc4c2781f3b5f77d6d48bff/app/src/main/java/dev/johnoreilly/fantasypremierleague/MainActivity.kt#L83 call. But, imagine if that was an endpoint call. This way, by each recomposition we're gonna call the endpoint multiple times. Right? or I'm missing here 🤔

Drjacky avatar Oct 08 '21 16:10 Drjacky

onPlayerSelected should only get invoked when you actually select a player in the list....are you seeing something different there? I'll take a closer look during the weekend....there could very likely be better ways of implementing some of the code there....I'm still learning Compose :)

joreilly avatar Oct 08 '21 16:10 joreilly

I looked into this last night with the new layout inspector tool which counts recompositions and found nothing out of order, so I think this could be closed unless you want to confirm John

HoinzeyBear avatar Sep 29 '22 19:09 HoinzeyBear