⚡
Recomposition in Jetpack Compose
List of practical tips and code snippets to avoid unnecessary recomposition in Jetpack Compose.
This is an active repo, please contribute if you discovered useful tips related to recomposition.
The first 5 tips were part of the talk "What does Recomposition mean to your app" by me:
Depth Level | Conference | Slides |
---|---|---|
Light | Connect Recharge'22 | Link |
Deep | Droidcon SF'22 | Link |
🔥
List of tips:
- Break down composable functions as much as possible;
- Use the key composable;
- Read the state value at the lowest composable function;
- Use Modifier lambdas for every frequent changing state read in Modifier functions;
- Use
derivedStateOf()
to buffer the rate of changes;
to be continued...
📌
Contribution
Contributions are more than welcome! The more we learn together Jetpack Compose, the faster we'll climb that learning curve
Here are some contribution rules to follow:
- Give the good and bad examples of the same output (see: each Tip file contains
GoodGreetings()
andBadGreetings()
composable functions); - Add the recompose highlighter & counter to every composable function via Modifier;
- Add comments in the beginning of the file to give the overview of the tip, then in subsequent good and bad sections.
Here are some contribution steps to follow:
- Clone this repository;
- Branch out via
git branch -b someBranchName
; - Open Android Studio (or any IDE you feel comfortable working with);
- Create a separate .kt file;
- Create a composable function, that starts with
TipX()
, whereX
= the last available number in the tip list + 1; - Write your tip;
- Modify the README doc and include your tip to the list;
- Push your tip and open the PR here.
Thank you so much for contributing and helping others to learn