Skip to content

Conversation

@yusufyildirim
Copy link
Collaborator

@yusufyildirim yusufyildirim commented Mar 25, 2025

This PR adds Android API 22 support to React Native 0.77 version.

Motivation

There are a lot of old Android devices in the TV hardware market still in use. Just like people are not replacing their TVs that often, they tend to not replace their smart TV hardwares. It's important to be able to provide service to those devices, if you want/need to.

Description

Most of the code changes in this PR are based on the old codes where RN was officially supporting older Android versions. You can go simply go check 0.73 branch, which is the latest RN version supporting API 22, for a given file to validate the approaches if you'd like. Although, there are a couple of exceptions needs explaining.

The changes in CompositeBackgroundDrawable.kt and BackgroundStyleApplicator.kt are based on their latest versions on the latest 0.79 RC branch. I basically copy-pasted those two files from the latest RC branch. Even though it looks and sounds weird, the reason behind it is quite simple. It roots back to this commit which heavily changes the way things are operated in those two files. It transitions things to use addLayer api (which requires API 23). This is the version of those files we have on the 0.77 branch. There's no easy way (as far as I'm aware) to get around this new addLayer api other than doing things the old way. Which means I need to convert things to the old way. It brings us to this commit. Good thing it's been done already on the 0.79 branch due to performance regression. The only thing I did is leveraging that and copying the work over here.

An another worth mentioning topic is that we have two new classes Drawable and LayerDrawable which inherit from their Android counterparts. They do only one thing extra, providing an API 22 compatible getLayoutDirection function.

There are tons of accesses to that function throughout the codebase. It would've been a nightmare to provide a local solution to every single one of them in their on file, on the spot. Instead of doing that, I created those two classes to "proxy" their Android SDK counterparts with minimal code change in the codebase. You'll see a bunch of import android.graphics.drawable.Drawable removal in the files while reviewing. Removing the Android SDK import statements makes Drawable and LayoutDrawable usages in those files to resolve to our own internal versions without requiring any extra change.

I tested the changes on an API 22 emulator and a real device using the RNTester app and our own company app. Did not encounter any issues.

@yusufyildirim yusufyildirim merged commit ac0fc9e into tvos-v0.77.0 Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants