Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-23 17:18:08 +03:00
parent 0928055213
commit adc1e2563d
6 changed files with 103 additions and 13 deletions

View file

@ -7,8 +7,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Icon
import androidx.compose.material.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.graphics.Color
@ -24,6 +23,7 @@ fun SimpleSettingsRow(
@DrawableRes icon: Int,
onItemsClick: () -> Unit,
modifier: Modifier = Modifier,
rowColors: RowColors = getDefaultRowColors(),
enabled: Boolean = true,
subtitle: String? = null,
) {
@ -41,24 +41,17 @@ fun SimpleSettingsRow(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
) {
val textColor: Color by animateColorAsState(
targetValue = if (enabled) {
TangemTheme.colors.text.primary1
} else {
TangemTheme.colors.text.secondary
},
)
Icon(
painter = painterResource(id = icon),
contentDescription = null,
modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing20),
tint = textColor,
tint = rowColors.iconColor(enabled = enabled).value,
)
Column(modifier = Modifier.padding(end = TangemTheme.dimens.spacing20)) {
Text(
text = title,
style = TangemTheme.typography.subtitle1,
color = textColor,
color = rowColors.titleColor(enabled = enabled).value,
)
AnimatedVisibility(
visible = !subtitle.isNullOrEmpty(),
@ -66,9 +59,75 @@ fun SimpleSettingsRow(
Text(
text = subtitle ?: "",
style = TangemTheme.typography.body2,
color = TangemTheme.colors.text.secondary,
color = rowColors.subtitleColor(enabled = enabled).value,
)
}
}
}
}
@Composable
fun getWarningRowColors(): RowColors = DefaultRowColors(
titleColor = TangemTheme.colors.text.warning,
iconColor = TangemTheme.colors.text.warning,
disabledTitleColor = TangemTheme.colors.text.secondary,
disabledIconColor = TangemTheme.colors.text.secondary,
)
@Composable
fun getDefaultRowColors(): RowColors = DefaultRowColors(
titleColor = TangemTheme.colors.text.primary1,
iconColor = TangemTheme.colors.text.primary1,
disabledTitleColor = TangemTheme.colors.text.secondary,
disabledIconColor = TangemTheme.colors.text.secondary,
)
@Immutable
private class DefaultRowColors(
private val titleColor: Color,
private val iconColor: Color,
private val disabledTitleColor: Color,
private val disabledIconColor: Color,
) : RowColors {
@Composable
override fun titleColor(enabled: Boolean): State<Color> {
return animateColorAsState(
targetValue = if (enabled) {
titleColor
} else {
disabledTitleColor
},
)
}
@Composable
override fun subtitleColor(enabled: Boolean): State<Color> {
return rememberUpdatedState(newValue = TangemTheme.colors.text.secondary)
}
@Composable
override fun iconColor(enabled: Boolean): State<Color> {
return animateColorAsState(
targetValue = if (enabled) {
iconColor
} else {
disabledIconColor
},
)
}
}
@Stable
interface RowColors {
@Suppress("TopLevelComposableFunctions")
@Composable
fun titleColor(enabled: Boolean): State<Color>
@Suppress("TopLevelComposableFunctions")
@Composable
fun subtitleColor(enabled: Boolean): State<Color>
@Suppress("TopLevelComposableFunctions")
@Composable
fun iconColor(enabled: Boolean): State<Color>
}

View file

@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
<path
android:pathData="M8.5,12H15.5"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
</vector>

View file

@ -312,6 +312,7 @@ internal object WalletPreviewData {
TokenActionButtonConfig(
text = TextReference.Str("Send"),
iconResId = R.drawable.ic_share_24,
isWarning = false,
onClick = {},
),
).toImmutableList(),

View file

@ -9,11 +9,13 @@ import com.tangem.core.ui.extensions.TextReference
* @property text text
* @property iconResId icon resource id
* @property onClick lambda be invoked when action component is clicked
* @property isWarning if warning row
* @property enabled enabled
*/
data class TokenActionButtonConfig(
val text: TextReference,
@DrawableRes val iconResId: Int,
val onClick: () -> Unit,
val isWarning: Boolean,
val enabled: Boolean = true,
)

View file

@ -98,7 +98,7 @@ internal class TokenActionsProvider(
}
is TokenActionsState.ActionState.HideToken -> {
title = resourceReference(R.string.token_details_hide_token)
icon = R.drawable.ic_trash_24
icon = R.drawable.ic_hide_24
action = { clickIntents.onHideTokensClick(cryptoCurrencyStatus) }
}
}
@ -106,6 +106,7 @@ internal class TokenActionsProvider(
text = title,
iconResId = icon,
onClick = action,
isWarning = actionsState is TokenActionsState.ActionState.HideToken,
enabled = actionsState.enabled,
)
}

View file

@ -10,6 +10,8 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter
import com.tangem.core.ui.components.SimpleSettingsRow
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.components.getDefaultRowColors
import com.tangem.core.ui.components.getWarningRowColors
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
@ -29,10 +31,16 @@ private fun ActionsBottomSheetContent(actions: ImmutableList<TokenActionButtonCo
Column(modifier = Modifier.background(TangemTheme.colors.background.primary)) {
actions.forEach { action ->
if (action.enabled) {
val rowColors = if (action.isWarning) {
getWarningRowColors()
} else {
getDefaultRowColors()
}
SimpleSettingsRow(
title = action.text.resolveReference(),
icon = action.iconResId,
enabled = action.enabled,
rowColors = rowColors,
onItemsClick = action.onClick,
)
}