Introducción a Jetpack Compose
Qué es Jetpack Compose
Configuración inicial del proyecto
Personalización de la UI con Material Design
Colores, Fuentes y Material Theme
Creación de Componentes de UI
Compose: Fases y Recomposición
Quiz: Personalización de la UI con Material Design
Composición de layouts en Jetpack Compose
Creación y abstracción modelos de dominio
Layouts: Column, Row y Box
Cómo utilizar Scaffold, TopAppBar, FAB y Listas
Vista de progreso personalizada con Canvas
Arquitectura de Acción - Estado - Evento en ViewModel
Ajustes en pantalla de lista de tareas
Quiz: Composición de layouts en Jetpack Compose
Construcción de funcionalidades
Pantalla de creación de tareas
Creación de Viewmodel para CreateTaskScreen
Quiz: Construcción de funcionalidades
Navegación en Jetpack Compose
Introducción a la navegación en Compose
Manejo de navegación con argumentos
Quiz: Navegación en Jetpack Compose
Creación de Bases de datos y dependencias
Creación de la base de datos con Room
Inyección de dependencias con Hilt
Quiz: Creación de Bases de datos y dependencias
Finalización de la app
Ajustes finales de UI para tu App
Demostración final de tu App
You don't have access to this class
Keep learning! Join and start boosting your career
Declarative UI offers many advantages, especially when working with tools such as Compose, but it also presents a major challenge: recomposition. Recomposition is the process by which the UI is re-generated each time there is a change of state in the underlying data. This phenomenon can have a significant impact on application performance and user experience if not handled properly.
To understand recomposition, we first need to dive into the Compose phases:
Node Creation Phase: With each change to the data, Compose generates nodes that represent the views and their hierarchy. This is where the state changes that trigger the recomposition are recorded, similar to how a data model is updated.
Layout Phase: Compose follows a specific algorithm to measure and place each element. First, it measures the composable's children and then calculates its own size based on those measurements. Modifiers such as padding and spacing are applied during this phase.
Rendering Phase: Finally, each composable is drawn pixel by pixel on the screen, completing the process visible to the user.
A common problem happens when composables are not optimally designed. For example, if multiple elements in the composition tree depend on the same variable, any change in this variable will trigger the recomposition of all corresponding views. This unnecessary regeneration of the composition tree can be costly, both in terms of time and resources, negatively affecting the user experience.
To deal with this challenge, certain optimization practices can be applied. A practical example is to separate composables into smaller, well-defined units. This can be achieved by following a design pattern where state variables influence only the required composables.
Consider the following malpractice scenario that causes unnecessary recompositions:
@Composable fun MalPracticeView(isShown: Boolean) { Column { Text("Text one") if (isShown) { Text("Text dependent on isShown") } } } } }
To optimize, we must adjust the schema of our composables:
@Composable fun OptimizedView(isShown: Boolean) { Column { Text("Text one") SecondTextComponent(isShown) } } } @Composable fun SecondTextComponent(isShown: Boolean) { if (isShown) { Text("Text dependent on isShown") } } }
In this optimized code, only SecondTextComponent
is guaranteed to depend on isShown
, avoiding unnecessary global Column
recompositions.
Using tools such as the "Layout Inspector" in the development environment helps to verify the recomposition phenomenon. You will be able to see specifically which components are affected in each interaction, giving you clear data to fine-tune your implementation and maximize performance.
Attention to detail and optimization of recompositions are crucial to developing efficient and user-friendly applications. As developers, we have mastered these techniques to radically improve both the quality of the user experience and the efficiency of the code.
Contributions 3
Questions 1
Want to see more contributions, questions and answers from the community?