When I first started working in Android TV in a project back in 2018, androidx was still a new thing and Leanback was the standard guide for building Android TV applications.
In fact, Leanback still is the recommended way by Google to build TV apps and the androidx libraries contain some helpers for TV UIs: https://developer.android.com/training/tv/start/start#tv-libraries
However, these libraries are too opinionated and not really flexible enough.
In this post I will go over the motivation for a new component for Android TV.
This year I switched jobs to another company that built an Android TV app based on Leanback’s
After working on a custom component for TV UIs in a previous project in 2018, I was disappointed to see Presenters everywhere
and some nasty workarounds to achieve UIs consisting of an header and a scrollable grid below.
After checking the release notes of leanback in the beginning of this year, I was a bit surprised to see that as of writing this post, the latest stable release of androidx.leanback was released in 2018-09-21.
This by itself wouldn’t be so bad, but we still have these issues open:
- HorizontalGridView crash when it’s in focus and updating list using DiffUtils
- Request the GridLayoutManager in Horizontal/VerticalGridView support SpanSizeLookUp
- NullPointerException on Leanback GridLayoutManager
We got an update in 2021 when Google eventually figured out that developers might just be interested in a good foundation for building UIs and decided to ship the
BaseGridView in a separate artifact:
However, by looking at the documentation and the issuetracker it seems like Google almost abandoned these libraries.
In this video below, you can see a single vertical RecyclerView supporting different span sizes on Android TV:
The standard use case of nested RecyclerViews as well:
Migrating from Leanback’s BaseGridView
I tried to keep the public API of DpadRecyclerView really similar to the one of BaseGridView so the migration should be pretty straightforward.
I wrote a detailed guide over here
Why not compose?
I decided against writing this in Compose because I predicted Google would write something similar.
In fact, there’s already something available in the official Android repo: androidx.tv.foundation
To avoid spending my time in vain writing something that will be supported by Google, I focused on writing this for the already stable RecyclerView and to provide an easy migration to existing apps.
I guess that a lot of TV apps might not ever migrate to Compose and this could be at least a way to fix the issues I mentioned above.
First alpha release
The first alpha release is now available on mavenCentral and you can check out the repo at: https://github.com/rubensousa/DpadRecyclerView