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

View file

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