Android’s layout system is now as old (10+ years) as the platform itself and has accrued technical debt during its many development iterations. Some of the problems with view widgets on the platform levels have been mitigated by Jetpack libraries (previously known as support libraries) which provide backwards compatibility across multiple Android versions. However, the layout system is still heavily influenced by its initial inheritance API approach which can be seen throughout all the classes in the Android’s Framework. e.g. EditText extends TextView which extends View. Where the View class is also reaching almost 30k lines of code.
React includes a declarative way to compose UI layouts and Leland Richardson attempted to create a cross language library to do the same across platforms. I attended his talk in 2018 and was fascinated by how he set-up Recoil. All his efforts led to what we now know as Compose.
Compose is a modern UI toolkit entirely written in Kotlin and provides a simplified and more efficient way of creating user interfaces. Before Compose you had to write layouts in XML which had its pros and cons. However, in reality XML proves to have more cons in terms of readability, flexibility and efficiency. Compose is designed to tackle many of the existing problems by:
Since there are already many blog posts about Compose this blog will not provide any examples. Google provides further information and a very nice tutorial at https://developer.android.com/jetpack/compose.
As an Android Developer & Technical Guide I am constantly investigating the new kid on the block, which could either be a new library, way of working or something different. With Compose it is the same and requires some time to be investigated and weighed.
There are multiple ways to decide whether a new tool is a good fit for you or your company:
I believe Compose is here to stay and, once it gets more traction and more widgets, will become the preferred way of creating layouts in Android. However, since it is in its early development there are still challenges to overcome. Some of the challenges I see I have written down as questions below:
This blog was written by
Jeffrey de Looff
Nov 15, 2019