Add Android API 22 support to version 0.77 #899
Merged
+350
−276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
addLayerapi 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
getLayoutDirectionfunction.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.Drawableremoval 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.