Status Update
Comments
be...@google.com <be...@google.com> #2
I'm not completely sure but his might be expected, as the buttons inside of the AndroidView might be consuming the down event, so it doesn't get propagated to the outter onKeyEvent modifier. ralu@ could you please confirm?
ra...@google.com <ra...@google.com> #3
I was able to reproduce this using this snippet:
import android.widget.Button as ButtonView
@Composable
fun TestBox(modifier: Modifier = Modifier) {
val requester = remember { FocusRequester() }
Row(modifier) {
Column(modifier = Modifier.focusGroup()) {
Button({}, modifier = Modifier.focusRequester(requester)) { Text("Button 1") }
Button({}) { Text("Button 2") }
}
Column {
Button({}) { Text("Button 3") }
AndroidView(
factory = { context ->
LinearLayout(context).apply {
orientation = LinearLayout.VERTICAL
addView(ButtonView(context).apply {
text = "Android Button 4"
setOnClickListener { requester.requestFocus() }
})
addView(ButtonView(context).apply { text = "Android Button 5" })
addView(ButtonView(context).apply { text = "Android Button 6" })
}
}
)
}
}
}
Step 1: Use the arrow keys to navigate to Buttton 4.
Step 2: Press enter (Trigger requester.requestFocus()).
Step 3: Observer that focus moves to Button 5 insteade of Button 1.
It looks like the onExit of Modifier.focusInteropModifier() intercepts the focus exit and performs a requestFocus(FOCUS_DOWN) instead:
George, can you help debug this further?
mo...@google.com <mo...@google.com>
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
Author: George Mount <
Link:
Fix several focus issues
Expand for full commit details
Fix several focus issues
Fixes: 369256395
Fixes: 378570682
Fixes: 376142752
Relnote: "Fixed several focus-related issues, including
crashes when IME tries to focus on ComposeView without
focusable items, focus change within child AndroidViews,
and focus request leaving an AndroidView."
Allow focus to leave AndroidView using requestFocus()
When requestFocus() is called to move focus from an
Android View within Compose to a compose focus requester,
the ComposeView should be focused and the focus target
should have focus.
This CL moves the functionality for moving focus
between child Views to the key handler, moveFocus(),
and requestFocus().
Test: new test, manual test
Change-Id: Ia03c3c04dc9fd9d55d8fcae6b15e15cb2384f467
Files:
- M
compose/ui/ui/api/current.txt
- M
compose/ui/ui/api/restricted_current.txt
- M
compose/ui/ui/src/androidInstrumentedTest/kotlin/androidx/compose/ui/focus/FocusViewInteropTest.kt
- M
compose/ui/ui/src/androidInstrumentedTest/kotlin/androidx/compose/ui/focus/OwnerFocusTest.kt
- M
compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeView.android.kt
- A
compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/FocusFinderCompat.android.kt
- M
compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/AndroidViewHolder.android.kt
- M
compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/FocusGroupNode.android.kt
- M
compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/ComposeUiFlags.kt
- M
compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/focus/FocusOwnerImpl.kt
- M
compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/focus/FocusTransactions.kt
Hash: 1467e40d3c1253ebb6e3b54f9bfdcdc93ef53da7
Date: Mon Dec 02 18:21:31 2024
pr...@google.com <pr...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.ui:ui:1.8.0-alpha08
androidx.compose.ui:ui-android:1.8.0-alpha08
androidx.compose.ui:ui-jvmstubs:1.8.0-alpha08
androidx.compose.ui:ui-linuxx64stubs:1.8.0-alpha08
Description
Jetpack Compose component used: AndroidView, Focus
Android Studio Build: uild #AI-233.14808.21.2331.11574862
Kotlin version: Latest
Steps to Reproduce or Code Sample to Reproduce:
1. See cl/690811317 MainActivity.kt
2. Create several buttons under AndroidView. And several buttons outside of AndroidView in compose
3. Add an onKeyEvent on AndroidView that request focus for the buttons in compose.
3. Press the key that set in the onKeyEvent. The focus will move to the next AndroidView button instead of buttons incompose.
Stack trace (if applicable):