From 7e02e72a40a654c2dd40b4106d907559c09bcc7c Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 16 Dec 2025 16:26:46 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../core/ui/components/fields/PinTextField.kt | 2 +- .../accesscode/AccessCodeComponent.kt | 12 +++++++++++ .../hotwallet/accesscode/AccessCodeModel.kt | 20 +++++++++++++------ .../accesscode/entity/AccessCodeUM.kt | 3 +++ .../hotwallet/accesscode/ui/AccessCode.kt | 9 ++++++++- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/fields/PinTextField.kt b/core/ui/src/main/java/com/tangem/core/ui/components/fields/PinTextField.kt index c348c0933f..9ee27e68ec 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/fields/PinTextField.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/fields/PinTextField.kt @@ -39,8 +39,8 @@ fun PinTextField( pinTextColor: PinTextColor, onValueChange: (String) -> Unit, modifier: Modifier = Modifier, + focusRequester: FocusRequester = remember { FocusRequester() }, ) { - val focusRequester = remember { FocusRequester() } val textFieldValue = remember(value) { TextFieldValue(value, selection = TextRange(value.length)) } diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt index ec2f7d3ca4..08693225cc 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt @@ -2,12 +2,16 @@ package com.tangem.features.hotwallet.accesscode import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.platform.LocalFocusManager import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.arkivanov.essenty.lifecycle.doOnResume import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.core.ui.event.EventEffect import com.tangem.core.ui.security.DisableScreenshotsDisposableEffect import com.tangem.features.hotwallet.accesscode.ui.AccessCode import com.tangem.domain.models.wallet.UserWalletId @@ -31,10 +35,18 @@ internal class AccessCodeComponent @AssistedInject constructor( @Composable override fun Content(modifier: Modifier) { val state by model.uiState.collectAsStateWithLifecycle() + val focusRequester = remember { FocusRequester() } + val focusManager = LocalFocusManager.current + + EventEffect(event = state.requestFocus) { + focusManager.clearFocus() + focusRequester.requestFocus() + } DisableScreenshotsDisposableEffect() AccessCode( modifier = modifier, + focusRequester = focusRequester, state = state, ) } diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt index 0e1efd5301..f08755fcab 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt @@ -7,6 +7,8 @@ import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.decompose.ui.UiMessageSender import com.tangem.core.ui.components.fields.PinTextColor +import com.tangem.core.ui.event.consumedEvent +import com.tangem.core.ui.event.triggeredEvent import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.message.DialogMessage import com.tangem.core.ui.message.EventMessageAction @@ -146,7 +148,11 @@ internal class AccessCodeModel @Inject constructor( title = resourceReference(R.string.access_code_alert_validation_cancel), onClick = { uiState.update { currentState -> - currentState.copy(onAccessCodeChange = ::onAccessCodeChange) + currentState.copy( + accessCode = "", + onAccessCodeChange = ::onAccessCodeChange, + requestFocus = triggeredEvent(Unit, ::consumeRequestFocusEvent), + ) } }, ), @@ -154,15 +160,17 @@ internal class AccessCodeModel @Inject constructor( title = resourceReference(R.string.access_code_alert_validation_ok), onClick = ::setNewCode, ), - onDismissRequest = { - uiState.update { currentState -> - currentState.copy(onAccessCodeChange = ::onAccessCodeChange) - } - }, + isDismissable = false, ), ) } + private fun consumeRequestFocusEvent() { + uiState.update { currentState -> + currentState.copy(requestFocus = consumedEvent()) + } + } + private suspend fun showErrorAndReset() { uiState.update { currentState -> currentState.copy( diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/entity/AccessCodeUM.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/entity/AccessCodeUM.kt index 1bc94c1d7c..978071789b 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/entity/AccessCodeUM.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/entity/AccessCodeUM.kt @@ -1,6 +1,8 @@ package com.tangem.features.hotwallet.accesscode.entity import com.tangem.core.ui.components.fields.PinTextColor +import com.tangem.core.ui.event.StateEvent +import com.tangem.core.ui.event.consumedEvent import com.tangem.features.hotwallet.accesscode.ACCESS_CODE_LENGTH internal data class AccessCodeUM( @@ -8,6 +10,7 @@ internal data class AccessCodeUM( val accessCodeColor: PinTextColor, val onAccessCodeChange: (String) -> Unit, val isConfirmMode: Boolean, + val requestFocus: StateEvent = consumedEvent(), ) { val accessCodeLength: Int = ACCESS_CODE_LENGTH } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCode.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCode.kt index 5d0526fe6b..ecfa44d9d6 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCode.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/ui/AccessCode.kt @@ -5,8 +5,10 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -20,7 +22,11 @@ import com.tangem.features.hotwallet.accesscode.entity.AccessCodeUM @Suppress("LongParameterList", "LongMethod") @Composable -internal fun AccessCode(state: AccessCodeUM, modifier: Modifier = Modifier) { +internal fun AccessCode( + state: AccessCodeUM, + modifier: Modifier = Modifier, + focusRequester: FocusRequester = remember { FocusRequester() }, +) { Column( modifier = modifier .fillMaxSize() @@ -77,6 +83,7 @@ internal fun AccessCode(state: AccessCodeUM, modifier: Modifier = Modifier) { value = state.accessCode, pinTextColor = state.accessCodeColor, onValueChange = state.onAccessCodeChange, + focusRequester = focusRequester, ) } }