Tools & tips to learn about recomposition in Jetpack Compose

Overview

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

📣 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;

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;
  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 💚 💚 💚

You might also like...
Showify is a my first simple ✅ Android application 📱 using DI, where I learn how to use dagger-hilt, retrofit2, mvvm, livedata, Requestly Interceptor
Showify is a my first simple ✅ Android application 📱 using DI, where I learn how to use dagger-hilt, retrofit2, mvvm, livedata, Requestly Interceptor

Showify is a my first simple ✅ Android application 📱 using DI, where I learn how to use dagger-hilt, retrofit2, mvvm, livedata, Requestly Interceptor and so much more...

Learn Kotlin, easy bites at a time
Learn Kotlin, easy bites at a time

Welcome! I hope you're having an amazing day! 🚀 This repository is a reference of how I think one should approach learning kotlin step-by-step. Insid

Purpose of this is to learn to create audit trail module.
Purpose of this is to learn to create audit trail module.

Redis Trail An effective audit trail solution can be crucial to an organization's security and data integrity as it can help find the who, what, and w

📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT 🖊️ NotyKT is the complete Kotlin-stack note taking 🖊️ application 📱 built to demonstrate a use of Kotlin programming language in server-side

 🍲Foodium is a sample food blog Android application 📱 built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, Flow, Dagger 2/Hilt, Architecture Components, MVVM, Room, Retrofit, Moshi, Material Components).
Kotlin-phoenix - A set of tools aimed to bridge Phoenix with the Kotlin Multiplatform world

Kotlin Phoenix This project is aimed to allow developers to work with Phoenix Ch

A starter project to build command-line tools in Kotlin Multiplatform
A starter project to build command-line tools in Kotlin Multiplatform

A starter project to build command-line tools in Kotlin Multiplatform Contains a re-implementation of a real world CLI tool: git-standup Installation

A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles
A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles

This repository serves as template and demo for building android applications for scale. It is suited for large teams where individuals can work independently on feature wise and layer wise reducing the dependency on each other.

Tools for Kotlin/Kscript to easy write shell command line in kotlin code

Kscript Tools Easy way to run shell command line in kotlin and other tools Usage Used in kscript: @file:DependsOn("com.sealwu:kscript-tools:1.0.2") Us

Comments
  • Tip3 lambda usage

    Tip3 lambda usage

    Hi,

    In the tip3, I think there's a potential catch that can trigger unncessary recompositions. The declaration of the lambda at this line:

    https://github.com/AidaIssayeva/recomposition_examples/blob/main/app/src/main/java/com/cupsofcode/recomposition_examples/Tip3.kt#L49

    When Tip3 is recomposed, even if the CardInfo value doesn't change, a new lambda will be created and passed to GoodGreetingsTip3, which will cause a complete recomposition down to GoodInnerColumn.

    This article is explaining why it happens and some solutions: https://proandroiddev.com/understanding-re-composition-in-jetpack-compose-with-a-case-study-9e7d96d98095

    This isn't exactly the topic of the tip, but since this is a very common case, I think it would be worth to fix it.

    The easy fix: GoodGreetingsTip3(cardInfo::value)

    Edit: might also be worth to add a comment to explain this

    opened by badoualy 2
Owner
Aida Issayeva
👩‍💻 Software Engineer 📣 Public speaker 👩‍🏫 Instructor 🤖 I build Android apps ✍️ and jot some thoughts on development and technology along the way.
Aida Issayeva
A sample Music Player project that help you learn about Compose in Android

Music App Compose UI A sample Music Player project that help you learn about Compose in Android. Note that this app only contain UI and has no logic.

Hamidreza Sahraei 25 Dec 13, 2022
A toy port scanner to help me (and you!) learn Kotlin + Akka.

kotlin-akka-portscan A toy program to help me (and you!) learn Kotlin + Akka. butwhy.gif When I want to learn a new language, I've found it helpful to

Jeremi M Gosney 4 Jul 23, 2022
Learn how to make an app designed for single-screen devices shine when running on foldable and dual-screen devices

dcberlin21-workshop Make your app shine om foldable devices with the samples we have here. Related links SDK open-source code SDK samples (Kotlin) App

Cesar Valiente 3 Oct 26, 2021
A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.

Apex Apex is just a simple proof of concept to demonstrate how easily you can build your own UI Toolkit from scratch. This code base is most likely fu

Romain Guy 79 Sep 7, 2022
A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.

Apex Apex is just a simple proof of concept to demonstrate how easily you can build your own UI Toolkit from scratch. This code base is most likely fu

Romain Guy 79 Sep 7, 2022
A project to learn about Reactive Microservices experimenting with architectures and patterns

reactive-microservices-workshop Copyright © 2021 Aleix Morgadas - Licenced under CC BY-SA 4.0 A project to learn about Reactive Microservices experime

Aleix Morgadas 7 Feb 21, 2022
A single screen app learn in google basic Android Development course.

Project: Lemonade App - Starter Code Starter code for the first independent project for Android Basics in Kotlin Introduction This is the starter code

Kaushal Raj 0 Dec 19, 2022
PlanetFacts - An educational android app for kids to learn about the planets in our solar system. Built with Kotlin.

PlanetFacts PlanetFacts is an offline simple, modern & material-designed educational Android application for kids. It contains basic facts with visual

Saikat Datta 1 Oct 16, 2022
Learn-kotlin - Learning more about Kotlin in various content

Kotlin study roadmap https://kotlinlang.org/docs/reference/ Getting Started Basi

Danilo Silva 0 Jan 7, 2022
Eton - Note taking app made to learn some good practices

Eton ?? Description Note taking app made to learn some good practices, from Phil

Vivek Sharma 2 Jan 20, 2022