You might have already heard about Jetpack Compose, as it is the most trending topic in Android Development. Still, let’s quickly define what it is! Well, Jetpack Compose is a declarative UI for native Android applications like Flutter and SwiftUI. It is built around Kotlin, and it has extensive support from Google.
What is declarative UI? 🤔
With declarative UI, we can tell our application what it should do and how it should look in a different state of an application, and that’s it. Now it will automatically update itself based on the states.
In simple words, we just provide them with the rules they need to follow, and based on that; they update themselves.
What’s in this blog?
Well, this will be a series of blogs where we will first see the pros and cons of Jetpack Compose. Then in the upcoming blogs, we will understand how to use some of the essential components(which we are already using in our Android development) in Jetpack Compose.
Pros of using Jetpack Compose : 😍
Let’s say you want to display a list of items in your app. Below are the steps that you must follow to achieve that :
– Declare your RecyclerView in XML.
– Create your custom views which will be shown in your RecyclerView cell.
– Create an adapter, and add OnCreate, OnBind, and other methods to display your cell.
– Finally, bind your RecyclerView with an adapter in your .kt/java file.
Isn’t that a bit tedious task?
Using Jetpack Compose, you can do it with a couple of lines of code. So let’s see how to do that:
And that’s it! This will display a list of 20 items in your app. See how easy it is!
Amazing, right? Yes, that’s what Jetpack Compose is. 🕺
Jetpack is already in use for production for many projects. But do you want to experiment with it in your current project, which consists of old XMLs? You can easily do it. You need to add a single component or a complete screen in your project without any changes.
Cons of using Jetpack Compose : 😥
AndroidViews.
Should we use Jetpack Compose in Production? 🤔
It totally depends on your project requirements. As mentioned earlier, if you are new to Compose and have a project deadline, you should probably avoid using it for the time being. But you can start using it in some of your side/small projects as Jetpack Compose is the future of Android development.
What will be in the upcoming series?
Conclusion:
In this article, we have seen what Jetpack Compose is and why we should use it. We have also seen some of the Pros and Cons of Jetpack compose.
Do you think you should use Jetpack Compose in your production environments? I definitely think that we should start using it in our small projects at least. Do let us know your views in the comments. 🤘
You can also check out this amazing repository: https://github.com/SimformSolutionsPvtLtd/SSComposeCookBook to check the collection of major UI components and sample screens built with Jetpack Compose.
If you have any suggestions, feedback, or doubts, feel free to comment below, or you can connect with me on Twitter or LinkedIn.
Source: Medium