PM-11356 Adjust autofocus delay to be greater than screen refresh delay. (#4866)

This commit is contained in:
Dave Severns
2025-03-14 12:48:34 -04:00
committed by GitHub
parent b084987758
commit 6fe9eba620
3 changed files with 12 additions and 6 deletions

View File

@@ -58,6 +58,7 @@ import java.time.Clock
import javax.inject.Inject
private const val SPECIAL_CIRCUMSTANCE_KEY = "special-circumstance"
private const val ANIMATION_REFRESH_DELAY = 500L
/**
* A view model that helps launch actions for the [MainActivity].
@@ -148,8 +149,7 @@ class MainViewModel @Inject constructor(
// Switching between account states often involves some kind of animation (ex:
// account switcher) that we might want to give time to finish before triggering
// a refresh.
@Suppress("MagicNumber")
delay(500)
delay(ANIMATION_REFRESH_DELAY)
trySendAction(MainAction.Internal.CurrentUserStateChange)
}
.launchIn(viewModelScope)
@@ -161,8 +161,7 @@ class MainViewModel @Inject constructor(
is VaultStateEvent.Locked -> {
// Similar to account switching, triggering this action too soon can
// interfere with animations or navigation logic, so we will delay slightly.
@Suppress("MagicNumber")
delay(500)
delay(ANIMATION_REFRESH_DELAY)
trySendAction(MainAction.Internal.VaultUnlockStateChange)
}

View File

@@ -70,7 +70,14 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.delay
import javax.crypto.Cipher
private const val AUTO_FOCUS_DELAY = 415L
/**
* Time slice to delay auto-focusing on the password/pin field. Because of the refresh that
* takes place when switching accounts or changing the lock status we want to delay this
* longer than the delay in place for sending those actions in [com.x8bit.bitwarden.MainViewModel]
* defined by `ANIMATION_REFRESH_DELAY`. We need to ensure this value is
* always greater.
*/
private const val AUTO_FOCUS_DELAY = 575L
/**
* The top level composable for the Vault Unlock screen.

View File

@@ -479,7 +479,7 @@ class VaultUnlockScreenTest : BaseComposeTest() {
@Test
fun `state with input and without biometrics should request focus on input field`() = runTest {
mutableStateFlow.update { it.copy(hideInput = false, isBiometricEnabled = false) }
dispatcher.advanceTimeByAndRunCurrent(500L)
dispatcher.advanceTimeByAndRunCurrent(600L)
composeTestRule
.onNodeWithText("Master password")
.performScrollTo()