ui: restore search focus when returning

Keep the query populated and put the cursor back at the end of the search field when the screen is restored.
This commit is contained in:
austinried
2026-10-19 13:06:27 +00:00
parent 4b3a7d1dfa
commit 2e54d09acb
2 changed files with 3 additions and 11 deletions
@@ -7,7 +7,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertIsNotFocused
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.StateRestorationTester
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
@@ -124,7 +123,7 @@ class SearchScreenTest {
}
@Test
fun restoringTheScreenDoesNotStealFocus() {
fun restoringTheScreenKeepsFocusOnTheQuery() {
val restorationTester = StateRestorationTester(composeRule)
restorationTester.setContent {
SubtracksTheme {
@@ -135,7 +134,7 @@ class SearchScreenTest {
composeRule.onNode(hasSetTextAction()).assertIsFocused()
restorationTester.emulateSavedInstanceStateRestore()
composeRule.onNode(hasSetTextAction()).assertIsNotFocused()
composeRule.onNode(hasSetTextAction()).assertIsFocused()
}
@Test