FantasyPremierLeague
FantasyPremierLeague copied to clipboard
Recomposition happens multiple time
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?
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.
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!
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 🤔
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 :)
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