I am Learning Android Compose, And I was looking/playing with this code from developers.android, in github. The projects is a simple app to demonstrate adaptive screen. Sports App
Everything works fine, but am a but confused.
I logged an item/line to Logcat. And I see that it gets executed twice? Recomposition? What is causing it?
In your code:
The
stringResourceandpainterResourcecan cause recomposition. In compose when something triggers a recomposition, it happens in the nearest scope.However the
Boxand theColumnare inline function, and it means that both don't have an own recompose scopes.In your code when the
Imageand theTextare recomposed all the composable is recomposed.If you change your
Columninto a customComposableit won't be recomposed.Something like:
and then: