Fixed
Status Update
Comments
pa...@google.com <pa...@google.com> #2
That's a great feedback. When we introduced this API we didn't have proper solution to check focus but we don have it now so it is a great opportunity to improve this.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit a0382346af6d557b8012e96121ae8d1508e63355
Author: Filip Pavlis <pavlis@google.com>
Date: Tue Feb 09 14:56:23 2021
Auto-detect focus for text actions.
We can now automatically detect if a text field has focus to avoid
sending a click there. This means the user no longer needs to manage
focus requests on their own.
Bug: 179648629
Test: Existing
Relnote: "Text actions now check focus automatically"
Change-Id: I13777ef805c71674b929577a3b794d655948da3f
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/textfield/TextFieldTest.kt
M compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt
M compose/ui/ui-test/api/current.txt
M compose/ui/ui-test/api/public_plus_experimental_current.txt
M compose/ui/ui-test/api/restricted_current.txt
M compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/TextActionsTest.kt
M compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/TextActions.kt
https://android-review.googlesource.com/1581447
Branch: androidx-main
commit a0382346af6d557b8012e96121ae8d1508e63355
Author: Filip Pavlis <pavlis@google.com>
Date: Tue Feb 09 14:56:23 2021
Auto-detect focus for text actions.
We can now automatically detect if a text field has focus to avoid
sending a click there. This means the user no longer needs to manage
focus requests on their own.
Bug: 179648629
Test: Existing
Relnote: "Text actions now check focus automatically"
Change-Id: I13777ef805c71674b929577a3b794d655948da3f
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/textfield/TextFieldCursorTest.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/textfield/TextFieldTest.kt
M compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt
M compose/ui/ui-test/api/current.txt
M compose/ui/ui-test/api/public_plus_experimental_current.txt
M compose/ui/ui-test/api/restricted_current.txt
M compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/TextActionsTest.kt
M compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/TextActions.kt
Description
The text editing test APIs (e.g.
performTextInput
) currently take a parameter calledalreadyHasFocus
, and when it's false (the default) they click the middle of the text field before attempting to perform input. I find that for any non-trivial tests involving aTextField
I almost always have to explicitly set this totrue
, because clicking in the middle of the text field puts the cursor in an essentially arbitrary position.I think a better API would fetch the current state of the node and only focus it if isn't already focused (and probably set the selection to something well defined, like the end of the text). If it's important for the text field to already be focused the writer of the test can use
assertIsFocused()
.