-
Notifications
You must be signed in to change notification settings - Fork 24.7k
TextInput does not blur in Android 8.1 with react native 0.79+ #51072
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
Comments
Warning Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:
You can read more about about it on our website: How to report a bug. |
Can you explain better? What do you mean with "TextInput does not blur"? |
The cursor pointer does not leave the first text input that finds in the screen. |
Can you share a video? |
No i dont know why. I will try later. The recreation is very easy. This is a clean react native template. You just have to run it on Android 8.1 device or even a virtual device. Add 2 TextInput and you will see that when you try to click outside the box the cusor pointer doesnt hide and even you try it in the 2nd 3rd input the cursor will move to first input of the screen. |
On both architectures. |
Looking forward to see the video |
Screen_recording_20250504_132904.mp4 |
Thanks for sharing the video @dlalas. What would be the expected behavior instead? |
The expected behavior should just be to blur the previously selected input and hide the cursor and not focus the first input of the screen (this is so weird). This is a same video on an Android 15 Screen_recording_20250506_163555.mp4 |
Ok so the issue is that the first TextInput is re-gaining the focus after you type on the first one. This happens only on Android 8.1. Correct? |
Yes only happening in Android 8.1 and only for react-native 0.79+ |
Summary: Reproducer for facebook#51072 Changelog: [Internal] [Changed] - Differential Revision: D74326426
ran into this same issue! on an android 7.1 edit: another repro, if necessary: https://github.com/goege64/reproducer-text-input-focus |
Thanks for the heads up @goege64 @joevilches can you look into this issue as you worked on |
@cortinico oh no! Yeah let me take a look and see if those changes broke something |
Oh, I think I ran into this issue as well! Glad to see it’s already been reported—I initially thought it was something caused by my use of the react-native-screens or reanimated beta versions. But after looking more closely, I realized the input stays focused, which prevents interaction with other elements inside the ScrollView. Definitely a significant issue. But no worries—these things happen (and it might not even be related to your change). @joevilches My test phone is on Android 8.0.0. Didn't experience this issue in my newer emulators. |
@goege64 how did you set this feature flag? |
@marcel-happyfloat I added this to my MainApplication.kt import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlagsDefaults and at the end of the onCreate function ReactNativeFeatureFlags.dangerouslyForceOverride(object : ReactNativeNewArchitectureFeatureFlagsDefaults() {
override fun useEditTextStockAndroidFocusBehavior(): Boolean = false
}) not sure if this causes other problems, because it does say dangerously, but on at least on 0.79 using the new architecture the result is ok from what i can tell |
@goege64 Thanks, it works! But I’m now really noticing the difference on newer Android devices — I have to tap twice to trigger something like the reaction modal in my chat scrollview: once to remove focus, and once for the actual action. It used to work instantly before applying this patch, but it’s definitely better this way than the other way around 😄 |
Update: checked yesterday and can confirm a repro on 8.1. From the looks of it the versions below also seem affected (8.0 and 7.1) but I didn't test those. When I was developing this initially I was on a much later version, which I do not see a repro on, so newer versions are not affected, although I'm not sure where the cutoff is exactly. I'm out today, but next week will dig into this a little more. I haven't developed non-RN android on a version this early, so not sure if this is stock android behavior for edit text, or there is some RN code causing this. That feature flag basically just allows Android to focus text inputs to allow for things like keyboard navigation into text inputs. So it could be that android just wants to focus the first text view at all points which seems weird, but unsure yet.
@marcel-happyfloat to clarify, are you saying setting this feature flag to false cause this problem? Or updating to this version before the feature flag swap causes this? |
@joevilches Yes, I believe so. Previously, before setting this flag to false (both RN v79.2), the input retained focus, but it still immediately triggered other interactions — unlike on the older devices. |
@marcel-happyfloat interesting. When that feature flag is false it should go back to behavior that has existed for a while in that edit text class so there may be something else at play as well. I'll keep an eye out. Do you mind showing me a video of what you are seeing? Would help me visualize some things. |
@joevilches sorry for the confusion. I think it is back to the expected behavior (same as iOS now), when setting this flag to false. Just tested some more and I think the current solution is also wrong for newer android phones.
|
UPDATE: So I found out that the bug is coming from the
I assume on earlier versions of Android there is a bug or feature where that note happens in touch-mode as well. The feature flag will enable behavior that just locks focusability for edit text components if its not from JS. So this auto focus call that comes from android would not do anything and is why that flag fixes things. This is problematic however because it also means we cannot use a hardware keyboard to focus this, which is what I was originally trying to fix. Gonna try to think of a solution that fixes both tomorrow. |
Summary: We got facebook#51072 (comment) which demonstrates that if we have 2 text inputs on a screen we cannot blur them. If you try to blur any, focus jumps to the first one. This seems to be a bug with Android's `clearFocus` per https://developer.android.com/reference/android/view/View#clearFocus(), this behavior is intended when we are not in touch mode, yet it happens regardless of what mode we are in on this version. I modified this a bit to swallow `requestFocus` calls if we are in touch mode. This should be fine as no JS focus calls will go through this path. On hardware keyboard focus and focus from `clearFocus` Changelog: [Android][Bugfix] - Fix bug where focus would jump to top text input upon clearing a separate text input. Differential Revision: D74678847
Summary: Pull Request resolved: #51302 We got #51072 (comment) which demonstrates that if we have 2 text inputs on a screen we cannot blur them. If you try to blur any, focus jumps to the first one. This seems to be a bug with Android's `clearFocus` per https://developer.android.com/reference/android/view/View#clearFocus(), this behavior is intended when we are not in touch mode, yet it happens regardless of what mode we are in on this version. I modified this a bit to swallow `requestFocus` calls if we are in touch mode. This should be fine as no JS focus calls will go through this path. On hardware keyboard focus and focus from `clearFocus` Changelog: [Android] [Fixed] - Fix bug where focus would jump to top text input upon clearing a separate text input. Reviewed By: mlord93 Differential Revision: D74678847 fbshipit-source-id: 12dcaf0c9c350d3ed697ff81e8dfb205b7942119
ok #51302 should fix this while also letting hardware keyboards work. I think I need to revert the feature flag removal and pick that into 0.80 though so there is a fix for this issue on all versions (since this one is slated for 0.81) |
Would it make sense to also pick that onto 0.79 since that's where the issue was first reported? |
@jvenene yeah good callout, I'll aim to pick the fix into 0.79 |
Description
TextInput does not blur in Android 8.1 with react native 0.79+ when clicked outside of the input anywhere. Though the keyboard closes.
More specifically i have 2 text inputs if i try to blur the second one it will focus the first one without opening the keyboard.
Steps to reproduce
React Native Version
0.79.2
Affected Platforms
Runtime - Android
Output of
npx @react-native-community/cli info
Stacktrace or Logs
MANDATORY Reproducer
.
Screenshots and Videos
The text was updated successfully, but these errors were encountered: