Skip to content

AidaIssayeva/recomposition_examples

Repository files navigation

⚡ 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 7 tips were part of the talk "What does Recomposition mean to your app" by me:

Depth Level Notes Conference Slides
Light Connect Recharge'22 Link
Deep (v1) Droidcon SF'22 Link
Deep (v2) Better visuals Chicago Roboto'22 Link
Deep (v3) Includes tips 6 and 7 Droidcon NYC'22 Link

📣 Don't forget to star ⭐ or watch 👀 the repo to get updates!

🔥 List of tips:

  1. Break down composable functions as much as possible;
  2. Use the key composable;
  3. Read the state value at the lowest composable function;
  4. Use Modifier lambdas for every frequent changing state read in Modifier functions;
  5. Use derivedStateOf() to buffer the rate of changes;
  6. Declare properties as read-only(val instead of var)
  7. Use KotlinX immutable collections instead of regular collection interfaces, like List, Map, Set, etc.

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:

  1. Give the good and bad examples of the same output (see: each Tip file contains GoodGreetings() and BadGreetings() composable functions);
  2. Add the recompose highlighter & counter to every composable function via Modifier or enable recomposition count in Android Studio Electric Eel's Layout Inspector;
  3. 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:

  1. Clone this repository;
  2. Branch out via git branch -b someBranchName;
  3. Open Android Studio (or any IDE you feel comfortable working with);
  4. Create a separate .kt file;
  5. Create a composable function, that starts with TipX(), where X = the last available number in the tip list + 1;
  6. Write your tip;
  7. Modify the README doc and include your tip to the list;
  8. Push your tip and open the PR here.

Thank you so much for contributing and helping others to learn 💚💚💚