Status Update
Comments
to...@unext.jp <to...@unext.jp> #2
We can't reproduce the issue with Compose 1.6.8.
to...@unext.jp <to...@unext.jp> #3
About workaround:
DON'T use FocusManager.clearFocus().
Instead of it, place a small composable like 1 dp height and move focus to it when you need to clear focus.
to...@unext.jp <to...@unext.jp> #4
First, we need to use EditText to work around the Compose 1.7 TextField issue below.
However, due to this focus issue, the Chromecast AndroidView button has always been in focus on Android 8.0 devices once the text is entered.
jo...@google.com <jo...@google.com>
to...@unext.jp <to...@unext.jp> #5
Apparently, Compose 1.7 has changed the behavior so that if EditText exists when the screen is opened, it will get focus. This may be the cause of the problem in this ticket.
an...@sigma.software <an...@sigma.software> #6
I experience a similar issue that involves keyboard and reproduces on a bunch of screens in my app with similar conditions. It takes a screen with any button, and a text field. Text field handles IME action (done/search), and executes FocusManager.clearFocus()
.
STR:
- Focus text field
- Press (dispatch) hardware
Enter
key (not IME search, or any IME action, but specifically hardwareEnter
)
ER: IME handler executes, focus gets cleared, that's it.
AR: IME handler executes, focus jumps to the hierarchically first button on the screen, and (important) performs a click on that button!
In my case I have a toolbar, and the first button is a back button inside the toolbar. Whenever the described scenario happens, a screen closes because the back button gets clicked!
Except, obviously, apps that directly support hardware input, this also affects:
- Emulator, since most of the time you type using hardware keyboard
- Instrumentation tests, since UiAutomator is incapable of dispatching IME actions directly
- Moreover, when running baseline profile generation on ATD emulator image, there is no emulated keyboard, and no IME button on the keyboard; I had to come up with a crutch to handle
Enter
key to make the test work
- Moreover, when running baseline profile generation on ATD emulator image, there is no emulated keyboard, and no IME button on the keyboard; I had to come up with a crutch to handle
an...@sigma.software <an...@sigma.software> #7
To further clarify my comment above, IME action (e.g. Done) alone in combination with FocusManager.clearFocus()
already focuses another (hierarchically first) view in the screen. But hardware Enter
key seems to be dispatching twice, therefore performs a click.
Description
1.7.4
Jetpack Compose component(s) used:
foundation
ui-viewbinding
material3
runtime
Android Studio Build:
Android Studio Ladybug | 2024.2.1 Patch 1
Build #AI-242.23339.11.2421.12483815, built on October 11, 2024
Runtime version: 21.0.3+-79915917-b509.11 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 13.3.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 8192M
Cores: 10
Metal Rendering is ON
Registry:
ide.instant.shutdown=false
debugger.new.tool.window.layout=true
ide.experimental.ui=true
i18n.locale=
Non-Bundled Plugins:
com.intellij.lang.jsgraphql (242.21829.3)
com.master.studio.plugin.adb_input (1.0.1)
wu.seal.tool.jsontokotlin (3.7.5)
idea.plugin.protoeditor (242.23339.11)
io.github.takahirom.roborazzi (1.8.0)
com.developerphil.adbidea (1.6.18)
com.mistamek.drawablepreview.drawable-preview (1.1.6)
com.suusan2go.kotlin-fill-class (1.0.23)
com.github.copilot (1.5.25.10)
Kotlin version:
2.0.20
Steps to Reproduce or Code Sample to Reproduce:
1. Build
2. Tap the EditText1
3. Tap the ClearFocus button
4. Reproduced! The EditText1 loses focus but immediately gains focus again
5. Tap the EditText2
6. Tap the ClearFocus button
7. Reproduced! The EditText2 loses focus but the EditText1 gains focus