declarative UI toolkit developed by Google for building native Android applications. It simplifies and accelerates UI development on Android by eliminating the need for XML-based layouts and enabling developers to build UIs directly in Kotlin code.
using key in lazy layouts •Observing continuously changing state in composables •Navigational issue •Loading Heavy Composables •Heavy operations in main thread •Unnecessary subcompositions •Recomposition due to unstable parameters
frequently, as often as for every frame of an animation. For this reason, you should do as little calculation in the body of your composable as you can.
an image from resources loads the image on the main thread during composition. This means that if your image is big, it can block the main thread with some work.
in layouts where you have much more items than the constrained size, they incur some additional cost, which is unnecessary when the lazy composition is not required.
or unstable. A type is stable if it is immutable, or if it is possible for Compose to know whether its value has changed between recompositions. A type is unstable if Compose can't know whether its value has changed between recompositions. • Stable parameters: If a composable has stable parameters that have not changed, Compose skips it. • Unstable parameters: If a composable has unstable parameters, Compose always recomposes it when it recomposes the component's parent.
use remember •Use Lazy layout keys •Use derivedStateOf to limit recompositions •Share data to other screens by using back stack entry •Accelerate heavy composables •Offload heavy operations to background thread •Remove unnecessary subcompositions •Always use stable parameters
list is sorted once, when ContactList is first composed. If the contacts or comparator change, the sorted list is regenerated. Otherwise, the composable can keep using the cached sorted list.
item lets Compose avoid unnecessary recompositions. Compose can determine the item now at spot 3 is the same item that used to be at spot 2. Since none of the data for that item has changed, Compose doesn't have to recompose it.
Compose which changes of state actually should trigger recomposition. In this case, specify that you care about when the first visible item changes. When that state value changes, the UI needs to recompose, but if the user hasn't yet scrolled enough to bring a new item to the top, it doesn't have to recompose.
the composable asynchronously. • The placeholder image had dimensions of 1600x1600px, which is clearly too big for what it shows. Changed it with vector and here are results: