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
stringResource
andpainterResource
can cause recomposition. In compose when something triggers a recomposition, it happens in the nearest scope.However the
Box
and theColumn
are inline function, and it means that both don't have an own recompose scopes.In your code when the
Image
and theText
are recomposed all the composable is recomposed.If you change your
Column
into a customComposable
it won't be recomposed.Something like:
and then: