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.
-
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.🖼️
- Recompose Highlighter: Highlights areas of the screen that recompose, helping developers visualize the impact of their code.
-
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.
-
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.
- 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.
- Clone the repository:
git clone https://github.com/AdamDawi/ComposeStabilityExamples
- Open the project in Android Studio.
- Be sure the versions in gradle are same as on github
Minimum version: Android 7 (API level 24) or later📱
Target version: Android 14 (API level 34) or later📱
Adam Dawidziuk🧑💻