Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReactEditText so it works with Android Emoji2 automatic support #33920

Closed

Conversation

designedbyz
Copy link

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 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

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)

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.

@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels May 26, 2022
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels May 26, 2022
@analysis-bot
Copy link

analysis-bot commented May 26, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 91452fc
Branch: main

@Dstiers11091
Copy link

jump

@designedbyz
Copy link
Author

No clue why that many tests all failed to run for that change, but happy to rebase on latest or whatever is needed.

@cortinico
Copy link
Contributor

Code looks good to me.
Could you rebase as you're far behind main.

@designedbyz designedbyz force-pushed the support-emoji-in-edit-text branch from 5752967 to fcde652 Compare May 31, 2022 16:49
@designedbyz
Copy link
Author

Code looks good to me.

Awesome, thanks!

Could you rebase as you're far behind main.

Haha, the distance is about the length of time I was waiting for the CLA to be signed, lol. Done!

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,788,336 +92
android hermes armeabi-v7a 7,191,921 +96
android hermes x86 8,099,700 +102
android hermes x86_64 8,077,200 +97
android jsc arm64-v8a 9,656,370 +65
android jsc armeabi-v7a 8,428,871 +62
android jsc x86 9,608,540 +62
android jsc x86_64 10,203,094 +67

Base commit: 91452fc
Branch: main

@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by Andy Zolyak in 92ebb29.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants