From 080b77fc6955cc69fea021dc0cf3ecdc62a0c48c Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 24 Oct 2023 11:30:53 +0200 Subject: [PATCH] Setup pin : let time for ui to refresh before switching to confirmation step --- .../impl/setup/SetupPinPresenter.kt | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenter.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenter.kt index 3c380e6be7..6472b4f1c2 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenter.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinPresenter.kt @@ -17,6 +17,7 @@ package io.element.android.features.lockscreen.impl.setup import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -27,6 +28,7 @@ import io.element.android.features.lockscreen.impl.setup.validation.PinValidator import io.element.android.features.lockscreen.impl.setup.validation.SetupPinFailure import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.core.meta.BuildMeta +import kotlinx.coroutines.delay import javax.inject.Inject class SetupPinPresenter @Inject constructor( @@ -48,29 +50,38 @@ class SetupPinPresenter @Inject constructor( var setupPinFailure by remember { mutableStateOf(null) } + LaunchedEffect(choosePinEntry) { + if (choosePinEntry.isComplete()) { + when (val pinValidationResult = pinValidator.isPinValid(choosePinEntry)) { + is PinValidator.Result.Invalid -> { + setupPinFailure = pinValidationResult.failure + } + PinValidator.Result.Valid -> { + // Leave some time for the ui to refresh before showing confirmation + delay(150) + isConfirmationStep = true + } + } + } + } + + LaunchedEffect(confirmPinEntry) { + if (confirmPinEntry.isComplete()) { + if (confirmPinEntry == choosePinEntry) { + //TODO save in db and navigate to next screen + } else { + setupPinFailure = SetupPinFailure.PinsDontMatch + } + } + } fun handleEvents(event: SetupPinEvents) { when (event) { is SetupPinEvents.OnPinEntryChanged -> { if (isConfirmationStep) { confirmPinEntry = confirmPinEntry.fillWith(event.entryAsText) - if (confirmPinEntry.isComplete()) { - if (confirmPinEntry == choosePinEntry) { - //TODO save in db and navigate to next screen - } else { - setupPinFailure = SetupPinFailure.PinsDontMatch - } - } } else { choosePinEntry = choosePinEntry.fillWith(event.entryAsText) - if (choosePinEntry.isComplete()) { - when (val pinValidationResult = pinValidator.isPinValid(choosePinEntry)) { - is PinValidator.Result.Invalid -> { - setupPinFailure = pinValidationResult.failure - } - PinValidator.Result.Valid -> isConfirmationStep = true - } - } } } SetupPinEvents.ClearFailure -> {