How To Studio

Lessons learned when migrating my app to Jetpack Compose | by Igor Escodro | Apr, 2021

Recently I decided to port the entire application. start, To Jetpack Compose. In particular, the first moment was very difficult because I had no experience with the declarative UI toolkit. But after some trial and error (and a lot of support from the community), development began to become easier and more intuitive in my mind. The purpose of this article is to share the lessons learned during the process and some references that have been of great help during development.

Alkaa is my playground and a safe place to test and learn many new tools without affecting my professional projects. If you want to know more about the importance of creating a personal app, see below. This article..

My first recommendation is not to implement Jetpack Compose in production applications right away. The framework is currently in beta and some critical bugs have been fixed prior to the stable release. As if that wasn’t enough obstacles (or if you’re reading this article after the stable release), Jetpack Compose brings a paradigm change to your tables. Declarative UI.

Some important concepts like Status, Winding up And Single Source of Truth It’s different from the traditional Android view and XML methods. Consider creating a sandbox project or moving one of your pet projects to create first. It helps you embrace the new paradigm more, learn what you should and shouldn’t do, make many mistakes, and build confidence during the process.

Another recommendation is that you don’t have to migrate your entire project to Jetpack Excellent interoperability Provided by Google, you can only migrate one activity or fragment at a time. That way, you can migrate only one flow, stabilize it, test it, and then move on.

What helped me a lot when migrating Alkaa to Jetpack Compose was the separation of concerns that the application already had. Once all the business logic was well separated from the view, one of the first commits was to remove all the code from the UI module.

All activities, fragments, ViewModels, and XML have been removed, but all business logic remains intact and can be used in a different user interface. In my case I want to use a new tool (see next section) so ViewModels has been removed and TDD.. If not, you should have been able to use it as is without any problems.

When migrating an existing project, one tip is to see how the UI and business logic are combined. Perhaps refactoring is needed to reduce this binding. This will make the transition smoother.

If you dive into a new world, why not try new tools and libraries?Sure, Compose supports LiveData, but what about? Use of flow instead of? If your project uses ReactiveX, it may be a good time to start learning coroutines.

With Compose’s interoperability, these new tools aren’t tightly bound, but learning new tools (especially in the sandbox) is a great way to build a variety of alternatives.

Unfortunately, I think the test is underestimated Overall. It’s very common to find articles on some uses of technology, but there are only a few ways to test it. As we start learning new toolkits like Compose, a game changer on how to create a UI, it’s also a great opportunity to learn how to test it from day 0.

If you are familiar with Espresso, there are many similarities with Compose Test. However, there are some differences (such as the lack of a unique identifier in Composable compared to the Android View System).android:id) You need to be careful about how to access the components.

Keep in mind that testing is a very important part of development. If you try to learn the test along with the development, everything will be easier in the future.

Do you remember when you first started developing on Android? All the unwanted nested layouts, some context leaks, is it hard to decide which code to leave where? You will probably face it again with Jetpack Compose. And that’s ok!

During application migration, I searched several times for very simple methods such as “How to center text in a view” and “How to create a round button”. Especially since it was my first time to use a declarative UI framework, I felt like I was learning how to develop on Android again.

Sometimes I was “stuck” when developing a feature because I didn’t know how to create a better or more scalable solution. The rule that helped me a lot in these times was “Keep swimming“. Creation is a very recent framework, so we didn’t have time to decide on best practices yet. So I set my goal as “Just make it workAfter that, I was able to debug and analyze performance and scalability. This also emphasizes the importance of developing in the sandbox. Now is the time to make a mistake..

Another point to develop with Compose, like other new technologies, is that there isn’t much content about it at this time. Perhaps it’s difficult to find examples and definitions during development. At the end of this article, there is a dedicated section with great content and references that helped a lot during the transition.

Also, many best practices and libraries were created in the middle of Android View System and Jetpack Compose. This is the same. There are already great tools, and more are coming. The community is working together to create great tools!

One of the important things in learning a new tool is to share new knowledge with the community. Sharing findings is important, especially with these new tools, as not enough content is yet available. Each obstacle you face and surely overcome will help many other developers.

In my case, I would have spent more time tackling the challenges I faced, especially without the support of a great community in Slack. Consider writing about some of the challenges you face, regardless of complexity. Did you have a hard time with BottomSheet? Did you find a better way to lift a component? Have you created an extension to help Composables? Someone in the community faces a similar problem and I am confident that your contribution will be of great help!

At the end of this article, there is a section that contains some useful resources that I found during my research. Please suggest more material that helped you during your process as well.

Learning new technologies is always challenging and can be disturbing to us, especially due to the frequency with which new tools are released. It makes no difference with Jetpack Compose, a new and illustrious tool that everyone is talking about. However, I think it will take some time before Compose becomes mainstream and is needed for professional projects. So be kind to yourself before tackling the challenges I faced with this. It’s a marathon, not a race. And making this task as collaborative as possible will definitely make it smoother for you and your fellow developers.


Leave a Reply

Your email address will not be published. Required fields are marked *