react-native-macos/ReactAndroid
Andy Zolyak 92ebb298e2 Fix ReactEditText so it works with Android Emoji2 automatic support (#33920)
Summary:
tldr; `ReactEditText` and Android's emoji support in Android's AppCompat 1.4.0 / 1.4.x conflict in an odd way, causing NPEs.

`ReactEditText` defines an `InternalKeyListener`, `mKeyListener`, that it uses to make sure input from all keyboards works correctly. This listener is normally initialized at the end of the constructor.

Unfortunately, some versions of `AppCompatEditText`, most notably the version in the App Compat `1.4.0-alpha0x`, the [minimum version required for the Play Store's emoji compliance](https://developer.android.com/guide/topics/ui/look-and-feel/emoji2#appcompat) call  `setInputType` from `AppCompatEditText`'s constructor. `ReactEditText` operates on the key listener inside of `setInputType` and since the `AppCompatEditText` constructor is called via call to `super` before the key listener is initialized, these versions of app compat can cause NPEs when used with React Native.

The fix is simple; check to see if `mKeyListener` is null, and initialize it if it is. This is necessary in both the constructor and inside of `setInputType`.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

https://github.com/facebook/react-native/wiki/Changelog

[Android] [Fixed] - NPE in `ReactEditText.setInputType` when React Native is used with some versions of a AppCompat 1.4.x. (and possibly others)

Pull Request resolved: https://github.com/facebook/react-native/pull/33920

Test Plan:
1. Build an app with both React Native and load it inside an app that is using AppCompat 1.4.x
2. Add a text field using React Native.
3. Open the screen of the app that contains the text field.

If you're working from this branch, you'll be fine. If you're working from main you'll get an NPE.

I can put together a test repo if needed.

Reviewed By: kacieb

Differential Revision: D36802622

Pulled By: cortinico

fbshipit-source-id: e7646da9a1ef0e0334152aecab0f972ca25092ec
2022-06-01 08:07:40 -07:00
..
hermes-engine Disable Javadoc publishing as it's currently failing on CI 2022-05-18 11:48:16 -07:00
libs Upgrade Android support library to version 28 in RN 2019-01-22 10:44:53 -08:00
src Fix ReactEditText so it works with Android Emoji2 automatic support (#33920) 2022-06-01 08:07:40 -07:00
.npmignore Do not publish Android tests inside the NPM package 2022-05-23 12:28:33 -07:00
Android-prebuilt.mk Bump boost for Android to 1.76 to align with iOS + fix (#33565) 2022-04-07 04:50:30 -07:00
DevExperience.md Fix Dead links to documents in the comments (#32619) 2021-11-22 03:31:10 -08:00
README.md docs: Fix dead links in README for rn-tester (#31901) 2021-07-27 11:01:47 -07:00
build.gradle Set root to be `..` for ReactAndroid 2022-05-23 09:40:29 -07:00
gradle.properties Bump boost for Android to 1.76 to align with iOS + fix (#33565) 2022-04-07 04:50:30 -07:00
proguard-rules.pro Cleanup OSS proguard rules and add @DoNotStripAny 2022-02-02 12:54:34 -08:00

README.md

Building React Native for Android

See the docs on the wiki.

Running tests

When you submit a pull request CircleCI will automatically run all tests. To run tests locally, see Testing.