Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-26 10:44:59 +04:00
parent bc30f9aa2e
commit b283f87b1b
2 changed files with 60 additions and 26 deletions

View file

@ -15,7 +15,7 @@ import dagger.assisted.AssistedInject
internal class DefaultAccountCreateEditComponent @AssistedInject constructor(
@Assisted appComponentContext: AppComponentContext,
@Assisted params: AccountCreateEditComponent.Params,
@Assisted private val params: AccountCreateEditComponent.Params,
) : AppComponentContext by appComponentContext, AccountCreateEditComponent {
private val model: AccountCreateEditModel = getOrCreateModel(params)
@ -24,8 +24,9 @@ internal class DefaultAccountCreateEditComponent @AssistedInject constructor(
override fun Content(modifier: Modifier) {
val state by model.uiState.collectAsStateWithLifecycle()
AccountCreateEditContent(
modifier = modifier,
state = state,
isCreateMode = params is AccountCreateEditComponent.Params.Create,
modifier = modifier,
)
BackHandler(onBack = state.onCloseClick)
}

View file

@ -1,22 +1,25 @@
package com.tangem.features.account.createedit.ui
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalFocusManager
@ -43,47 +46,40 @@ import com.tangem.features.account.createedit.entity.AccountCreateEditUM
import com.tangem.features.account.createedit.entity.AccountCreateEditUM.Account
import kotlinx.collections.immutable.toImmutableList
@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun AccountCreateEditContent(state: AccountCreateEditUM, modifier: Modifier = Modifier) {
internal fun AccountCreateEditContent(
state: AccountCreateEditUM,
isCreateMode: Boolean,
modifier: Modifier = Modifier,
) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current
Column(
modifier = modifier
.background(color = TangemTheme.colors.background.secondary)
.fillMaxSize()
.verticalScroll(rememberScrollState())
.imePadding()
.systemBarsPadding(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
AppBarWithBackButton(
text = state.title.resolveReference(),
onBackClick = state.onCloseClick,
iconRes = R.drawable.ic_close_24,
modifier = Modifier.height(TangemTheme.dimens.size56),
)
AppBar(title = state.title, onBackClick = state.onCloseClick)
Column(
modifier = Modifier
.padding(horizontal = 16.dp)
.weight(1f),
) {
AccountSummary(state.account)
AccountSummary(state.account, isCreateMode)
SpacerH24()
AccountColor(state.colorsState)
SpacerH24()
AccountIcons(state.iconsState)
SpacerH8()
Text(
modifier = Modifier.padding(horizontal = 8.dp),
text = state.account.derivationInfo.text.resolveReference(),
style = TangemTheme.typography.caption2,
color = TangemTheme.colors.text.tertiary,
)
}
if (state.buttonState.shouldShowProgress) {
focusManager.clearFocus()
keyboardController?.hide()
DerivationInfo(text = state.account.derivationInfo.text)
}
PrimaryButton(
modifier = Modifier
.fillMaxWidth()
@ -94,10 +90,29 @@ internal fun AccountCreateEditContent(state: AccountCreateEditUM, modifier: Modi
onClick = state.buttonState.onConfirmClick,
)
}
SideEffect {
if (state.buttonState.shouldShowProgress) {
focusManager.clearFocus()
keyboardController?.hide()
}
}
}
@Composable
private fun AccountSummary(account: Account) {
private fun AppBar(title: TextReference, onBackClick: () -> Unit) {
AppBarWithBackButton(
text = title.resolveReference(),
onBackClick = onBackClick,
iconRes = R.drawable.ic_close_24,
modifier = Modifier.height(TangemTheme.dimens.size56),
)
}
@Composable
private fun AccountSummary(account: Account, isCreateMode: Boolean) {
val focusRequester = remember { FocusRequester() }
Column(
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
@ -142,9 +157,16 @@ private fun AccountSummary(account: Account) {
account.onNameChange(newName)
},
textFieldModifier = Modifier.focusRequester(focusRequester),
)
SpacerH(20.dp)
}
LaunchedEffect(Unit) {
if (isCreateMode) {
focusRequester.requestFocus()
}
}
}
@Suppress("LongMethod", "MagicNumber")
@ -162,8 +184,9 @@ private fun AccountColor(colorsState: AccountCreateEditUM.Colors) {
columns = columns,
contentPadding = contentPadding,
horizontalArrangement = Arrangement.spacedBy(4.dp),
userScrollEnabled = false,
) {
itemsIndexed(colorsState.list) { index, color ->
items(colorsState.list) { color ->
val isSelected = color == colorsState.selected
Box(
contentAlignment = Alignment.Center,
@ -282,12 +305,22 @@ private fun AccountIcons(iconsState: AccountCreateEditUM.Icons) {
}
}
@Composable
private fun DerivationInfo(text: TextReference) {
Text(
modifier = Modifier.padding(horizontal = 8.dp),
text = text.resolveReference(),
style = TangemTheme.typography.caption2,
color = TangemTheme.colors.text.tertiary,
)
}
@Preview(showBackground = true, widthDp = 360)
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun WcConnectionsContentPreview(@PreviewParameter(PreviewStateProvider::class) params: AccountCreateEditUM) {
TangemThemePreview {
AccountCreateEditContent(state = params)
AccountCreateEditContent(state = params, isCreateMode = true)
}
}