Status Update
Comments
ra...@google.com <ra...@google.com> #2
The Window focus API landed in aosp/1492096. This unblocks this task.
You can use AmbientWindowManager.current.isWindowFocused
to access window focus state or WindowFocusObserver{ hasFocus-> {...} }
if you want to be notified whenever there is a window focus change.
si...@google.com <si...@google.com> #3
I believe ideally cursor should not show up when there is no focus.
so...@google.com <so...@google.com>
so...@google.com <so...@google.com> #4
Checked a few existing apps. Looks like we stop animating the cursor whenever a window looses its focus. But some don't do that continuing to animate the cursor similar to current Compose behavior. The latter example was a log-in screen in the 1p app, my suspicion is that it just shows the web page
al...@jetbrains.com <al...@jetbrains.com> #5
When the 2nd textfield is in a Dialog
, both will continue blinking:
Column(Modifier.fillMaxSize()){
val focusRequester = remember { FocusRequester() }
TextField(
value = "",
onValueChange = { },
modifier = Modifier.focusRequester(focusRequester)
)
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
var showDialog by remember { mutableStateOf(false) }
Button(
onClick = { showDialog = true },
modifier = Modifier
.focusProperties {
canFocus = false
}
) {
Text("Open Dialog")
}
if (showDialog) {
Dialog(
onDismissRequest = { showDialog = false },
) {
Surface (
elevation = 20.dp
) {
Box(Modifier.padding(40.dp)) {
val dialogFocusRequester = remember { FocusRequester() }
TextField(
value = "",
onValueChange = { },
modifier = Modifier.focusRequester(dialogFocusRequester)
)
LaunchedEffect(Unit){
dialogFocusRequester.requestFocus()
}
}
}
}
}
}
(note that the button needs to be non-focusable, so it doesn't steal it when clicked).
ap...@google.com <ap...@google.com> #6
Branch: androidx-main
commit ffda3387e1f1bac619e1ff04cd3caf0a44257607
Author: Anastasia Soboleva <soboleva@google.com>
Date: Fri Oct 06 17:54:58 2023
Cursor, cursor handle and selection handles will now disappear when window loses focus
When textfield is in focus but window loses its focus, the textfield will preserve its focus but it will stop animating the cursor and will dismiss the cursor/selection handles.
If there's a selection, it will continue to be drawn (as a background) but handles/toolbar will disappear.
This also fixes a bug where previously toolbar never appeared back after window regained focus because we didn't restart the input session.
There're a lot of changes in the tests but most of them (apart from those that test the new functionality) simply updated to use the `rule.setTextFieldTestContent` which propagates the WindowInfo with the isWindowFocused==true.
Bug: 170977431
Test: multiple new tests + a demo
Change-Id: Ia09393e503061c39d6b909981caf723b500e3588
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextFieldCursorBlinkingDemo.kt
A compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text2/CursorDemos.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/CoreTextFieldSelectionOnBackTest.kt
A compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/FocusedWindowTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/AbstractSelectionMagnifierTests.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/TextFieldVisualTransformationMagnifierTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/gestures/AbstractSelectionGesturesTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/BasicTextField2ImmIntegrationTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/BasicTextField2SemanticsTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/BasicTextField2Test.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldCursorTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldKeyboardActionsTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/TextFieldScrollTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldClickToMoveCursorTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldCursorHandleTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldLongPressTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldMagnifierTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldSelectionHandlesTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldSelectionOnBackTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldTextToolbarTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldScrollTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldSelectionTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldVisualTransformationCursorTest.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/textfield/TextFieldVisualTransformationSelectionBoundsTest.kt
M compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/text2/input/internal/selection/AndroidTextFieldMagnifier.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreTextField.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/BasicTextField2.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/input/internal/TextFieldCoreModifier.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/input/internal/TextFieldDecoratorModifier.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/input/internal/selection/TextFieldSelectionState.kt
M compose/material/material/src/androidInstrumentedTest/kotlin/androidx/compose/material/MaterialTest.kt
M compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/MaterialTest.kt
so...@google.com <so...@google.com>
pr...@google.com <pr...@google.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.foundation:foundation:1.6.0-alpha08
androidx.compose.foundation:foundation-android:1.6.0-alpha08
androidx.compose.foundation:foundation-desktop:1.6.0-alpha08
androidx.compose.material:material:1.6.0-alpha08
androidx.compose.material:material-android:1.6.0-alpha08
androidx.compose.material:material-desktop:1.6.0-alpha08
androidx.compose.material3:material3:1.2.0-alpha10
androidx.compose.material3:material3-android:1.2.0-alpha10
androidx.compose.material3:material3-desktop:1.2.0-alpha10
so...@google.com <so...@google.com> #9
Note that in tests/screenshot tests the cursor might not be visible since WindowInfo#isWindowFocused
might not report true
at the time the assertion is run (see
Description
In a multi-window scenario, we could have two text fields in two different windows. In this scenario, both the text fields should show the cursor (Both text fields are focused), but only one of them is active (The one in the active window). The active text field receives key input, and the other one does not. Right now, we don't have any visual difference when the window loses focus, so the user will see two identical blinking cursors.
Can we gray-out the cursor and stop blinking when the window loses focus?