react-native: TextInput does not blur in Android 8.1 with react native 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

  1. Just clean build a react native template with with react native 0.79+. Even with the latest one 0.79.2

React Native Version

0.79.2

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: Windows 11 10.0.26100
  CPU: "(16) x64 AMD Ryzen 7 5800X 8-Core Processor             "
  Memory: 23.30 GB / 63.92 GB
Binaries:
  Node:
    version: 23.9.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.9.2
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: Not Found
  Visual Studio: Not Found
Languages:
  Java:
    version: 17.0.8.1
    path: /cygdrive/c/Program Files/Eclipse Adoptium/jdk-17.0.8.101-hotspot/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

Nothing is logged in logcat.

MANDATORY Reproducer

.

Screenshots and Videos

Image

Image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 34 (16 by maintainers)

Commits related to this issue

Most upvoted comments

ok long saga here but I think we can close this now. Fix is in 0.79 and 0.80. Thanks for bringing this up!

@irekrog hey sorry for the delays here I got caught up with a few other tasks. I have a commit out on my fork. I just need to test since this was a nontrivial merge, and create a PR in react-native for review. I’ll aim to get that done tomorrow

Yeah I think we should try to pick these changes into 0.79. It it challenging since 0.79->0.80 the text input file moved from java to kotlin so it might be a bit messy but we should be able to do it still. I’ll reopen and try to take that on this week

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)

@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

Tried out 0.80.0-rc.3 and the issue does seem to be fixed! thank you.

UPDATE: So I found out that the bug is coming from the clearFocus() call we make, which calls into super.clearFocus() which is https://developer.android.com/reference/android/view/View#clearFocus(). If you read the note there it says:

When not in touch-mode, the framework will try to give focus to the first focusable View from the top after focus is cleared. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view.

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.

@cortinico oh no! Yeah let me take a look and see if those changes broke something

Thanks for the heads up @goege64

@joevilches can you look into this issue as you worked on useEditTextStockAndroidFocusBehavior ?