Skip to content

Stability and recomposition in Jetpack Compose with examples

Notifications You must be signed in to change notification settings

AdamDawi/ComposeStabilityExamples

Repository files navigation

Compose Stability Examples

Dive into the world of Jetpack Compose with the Compose Stability Examples project, which showcases best practices and common pitfalls related to stability and recomposition. This project and its insights were inspired by the blog article The Do’s and Don’ts of Jetpack Compose. Special thanks to the author for providing practical examples and best practices.

⭐️Features

Main Screen

  • Slider Interaction: A responsive slider that dynamically updates UI components, showcasing how to handle recomposition efficiently.

  • LazyVerticalGrid: Learn how recompositions are triggered by different state changes.

  • Dialog with Image: Click on any example to view a dialog with an associated image, demonstrating code of particular example.🖼️

Visual Feedback

  • Recompose Highlighter: Highlights areas of the screen that recompose, helping developers visualize the impact of their code.

Stability Examples

  • Stable Examples: Properly implemented composables using immutable data structures or stable objects, ensuring optimal recomposition behavior.

    Key Point: If a class is marked as stable, it uses structural equality (.equals()) to detect changes, ensuring precise and efficient recomposition.

  • Unstable Examples: Common issues in Compose, such as passing mutable or frequently changing data, leading to excessive recompositions.

    Key Point: If a class is unstable, it uses referential equality (===), which may result in unnecessary recompositions when data is updated but not replaced.

⚙️Technologies

📱App:

  • Jetpack Compose: A modern toolkit for building native Android UIs with declarative components. 🎨

  • Persistent Data Structures: Leveraging immutable collections to enhance stability and prevent unnecessary recompositions.

🎯 Goals

  • Show how parameters in composables impact recomposition and performance.
  • Highlight the difference between stable and unstable parameters in composables and their effect on recomposition.
  • Provide insights on handling state, immutability, and stability annotations to optimize UI rendering.

Installation

  1. Clone the repository:
git clone https://github.com/AdamDawi/ComposeStabilityExamples
  1. Open the project in Android Studio.
  2. Be sure the versions in gradle are same as on github

Here are some overview pictures:

11 22 33 44

Requirements

Minimum version: Android 7 (API level 24) or later📱

Target version: Android 14 (API level 34) or later📱

Author

Adam Dawidziuk🧑‍💻

About

Stability and recomposition in Jetpack Compose with examples

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages