Warming up
Hello mates 👋, I am back with another article on why one should choose Jetpack Compose over legacy XML for designing and development of UI on Android devices. First I'll try to convince you with help of some example of major players who are using Jetpack Compose currently, hopefully you'll be convinced by that but if not, then I'll be getting into some technical details for choosing Compose over XML.
Let's get started....
Testimonials
Let's see some testimonials who uses Jetpack Compose Note: Click here to know the Source
Before diving into WHY jetpack compose we should be clear about what Jetpack Compose is in the first place.
What is Jetpack Compose?
Android Developer's document describes here and I quote
Jetpack Compose is Android’s modern toolkit for building native UI. It simplifies and accelerates UI development on Android bringing your apps to life with less code, powerful tools, and intuitive Kotlin APIs. It makes building Android UI faster and easier. While creating Compose we worked with different partners who experienced all of these benefits first hand and shared some of their takeaways with us.
Using the declarative approach for build native UI, Using Jetpack Compose we can achieve same designs with lot less code. UI modules are more decoupled, powerful as well as reusability is at another level. With Legacy approach with XML, we have to write more and more of boilerplate code as well as the code was longer than anything else. So it's always better to get better results as well as better performance and that too with less lines of code hence better productivity and efficiency.
Why should we use Jetpack Compose?
Jetpack Compose comes with 4 most impactful reasons
- Less code
- Intuitive
- Accelerate development
- Powerful
Less code
Writing tons of lines of code for UI blocks your time from working on some of the most critical functionalities of your app then needs more focus than ever. More lines of code mean more chances of bugs, more code to test and debug, more code to review, understand , maintain and what not. On the other hand, Compose allows us to achieve more with less code.
Intuitive
Compose uses declarative API and with the help of this we only need to do is describe our UI, Compose takes care of everything else. The components that we build with Compose are not tied to a specific activity or fragment, which makes it easy to reuse and test. The state is explicit and passed to the composable method and this ensures a single source of truth for the state making it encapsulated and decoupled. With the change of app state our UI automatically updates.
Accelerate development
Compose is compatible with our existing code, we can call Compose code from any Views and vice-versa. With such speed and interoperability we don't have to think about light/dark modes or anything else. It all works so seamless. Also when working on some custom views and going through whole process of building the app and checking it inside an emulator or an Android device multiple times is now gone. We can build multiple previews with different states together like a component in light/dark mode, a button in enabled or disabled state all these previews can be seen instantly and this saves a lot of our time.
Powerful
With Compose we get direct access to the Android platform APIs and built-in support for Material Design, Dark theme, animations, accessibility APIs and more. The process from how we want to design and how we actually design is now narrowed down to almost nothing. Adding animations was a big scary thing earlier when dealing with XMLs UI. Jetpack Compose simplified it almost as easy as designing a static UI.
❤️Finally
I hope I convinced you for using Jetpack Compose for your next projects and even for existing projects that you've been working on. To learn more about how you can use Jetpack Compose in your existing project, Follow and Subscribe to the newsletter and I'll be soon writing a full series of starting with Jetpack Compose and using it fullfledged for your App. Let me know by writing comments and leave a clap if you think it was helpful.
Thanks :) Be safe, Keep coding Cheers!
Resources