Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-23 18:09:23 +04:00
parent df938519a2
commit d18d87f41e
3 changed files with 53 additions and 9 deletions

View file

@ -11,6 +11,7 @@ internal data class CustomTokenFormUM(
val tokenForm: TokenFormUM?,
val notifications: ImmutableList<NotificationUM> = persistentListOf(),
val canAddToken: Boolean = false,
val isValidating: Boolean = false,
val saveToken: () -> Unit,
) {
@ -32,6 +33,7 @@ internal data class TextInputFieldUM(
val placeholder: TextReference,
val value: String = "",
val error: TextReference? = null,
val isEnabled: Boolean = true,
val onValueChange: (String) -> Unit,
)

View file

@ -11,11 +11,11 @@ import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
@ -82,6 +82,7 @@ internal fun CustomTokenFormContent(model: CustomTokenFormUM, modifier: Modifier
.fillMaxWidth(),
text = stringResource(id = R.string.custom_token_add_token),
enabled = model.canAddToken,
showProgress = model.isValidating,
onClick = model.saveToken,
)
}
@ -159,14 +160,25 @@ private fun TextField(
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
) {
var isFocused by remember { mutableStateOf(value = false) }
InformationBlock(
modifier = modifier,
title = {
val color by animateColorAsState(
targetValue = if (model.error != null) {
TangemTheme.colors.text.warning
} else {
TangemTheme.colors.text.tertiary
targetValue = when {
!model.isEnabled -> {
TangemTheme.colors.text.disabled
}
model.error != null -> {
TangemTheme.colors.text.warning
}
model.value.isNotBlank() || isFocused -> {
TangemTheme.colors.text.tertiary
}
else -> {
TangemTheme.colors.text.disabled
}
},
label = "Field label color",
)
@ -178,14 +190,27 @@ private fun TextField(
)
},
content = {
val color by animateColorAsState(
targetValue = if (model.isEnabled) {
TangemTheme.colors.text.primary1
} else {
TangemTheme.colors.text.disabled
},
label = "Field value color",
)
SimpleTextField(
modifier = Modifier
.padding(bottom = TangemTheme.dimens.spacing12)
.fillMaxWidth(),
.fillMaxWidth()
.onFocusChanged {
isFocused = it.isFocused
},
value = model.value,
color = color,
onValueChange = model.onValueChange,
readOnly = false,
placeholder = model.placeholder,
readOnly = !model.isEnabled && !isFocused,
singleLine = true,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
@ -236,7 +261,16 @@ private class PreviewCustomTokenFormComponentProvider :
override val values: Sequence<PreviewCustomTokenFormComponent>
get() = sequenceOf(
PreviewCustomTokenFormComponent(),
PreviewCustomTokenFormComponent(
tokenForm = PreviewCustomTokenFormComponent.tokenForm.copy(
contractAddress = TextInputFieldUM(
label = stringReference("Contract address"),
value = "0x1234567890",
placeholder = stringReference("0x1234567890"),
onValueChange = {},
),
),
),
PreviewCustomTokenFormComponent(
tokenForm = PreviewCustomTokenFormComponent.tokenForm.copy(
contractAddress = TextInputFieldUM(

View file

@ -44,8 +44,10 @@ import com.tangem.core.ui.components.rows.BlockchainRow
import com.tangem.core.ui.components.rows.ChainRow
import com.tangem.core.ui.components.rows.model.BlockchainRowUM
import com.tangem.core.ui.components.rows.model.ChainRowUM
import com.tangem.core.ui.components.snackbar.TangemSnackbarHost
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.res.LocalSnackbarHostState
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.core.ui.utils.WindowInsetsZero
@ -93,6 +95,12 @@ internal fun ManageTokensScreen(state: ManageTokensUM, modifier: Modifier = Modi
state = state,
)
},
snackbarHost = {
TangemSnackbarHost(
modifier = Modifier.padding(all = TangemTheme.dimens.spacing16),
hostState = LocalSnackbarHostState.current,
)
},
floatingActionButtonPosition = FabPosition.Center,
floatingActionButton = {
if (state is ManageTokensUM.ManageContent) {