Say Hello to Jetpack Compose and Compare with XML
Introduction
Hi everyone 👋 I will try to explain Jetpack Compose Fundamentals and Why should I use Jetpack Compose. Jetpack Compose is important because it is a new way of building modern UI in Android. Let’s dive into the UI development in Android without XML.
In my opinion, Jetpack Compose is the future of Android UI development and we must adopt fastly.
What is Jetpack Compose?
Jetpack Compose is Android’s modern toolkit for building native UI. It simplifies and accelerates UI development on Android – Google
Jetpack Compose is a modern toolkit that allows us to build our screens in a declarative approach writing less code. Android UI Development is now more powerful and more decoupled.
Before Jetpack Compose, we were using XML layouts to build the native UI. We had a very dependent structure when we build the screens with XML. Also, fragments are very heavy components for the UI. Jetpack Compose allows us to build the same UI with a declarative UI approach and with less code.
Why should I use Jetpack Compose?
In my opinion, it’s more than easy from XML and Kotlin ❤️
If we look technically:
- Declarative UI is cleaner, readable, and performant than Imperative UI.
- Compose allows you to do more with less code compared to XML.
- Compose is Intuitive. This means that you just need to tell Compose what you want to show the user.
- Compose is compatible with all your existing code: you can call Compose code from Views and Views from Compose. Also integrated with many Jetpack Libraries.
- Compose improves your build time and APKÂ size.
XML Design vs Jetpack Compose
Composition — Recomposition — State Management
Each composables has a initial compositon. Initial composition runs only when we see a view at first time in screen.
Composables can hold a state and re-run on state changes. This is called Recomposition.