Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-23 14:48:16 +08:00
parent d630852c29
commit 30ed01cb2f
6 changed files with 13 additions and 273 deletions

View file

@ -1,176 +0,0 @@
package com.tangem.core.ui.components
import android.content.res.Configuration
import androidx.annotation.DrawableRes
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.tangem.core.ui.R
import com.tangem.core.ui.res.ButtonColorType
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TextColorType
import com.tangem.core.ui.res.buttonColor
import com.tangem.core.ui.res.textColor
@Preview(widthDp = 328, heightDp = 48, showBackground = true)
@Preview(widthDp = 328, heightDp = 48, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun Preview_PrimaryStartIconButton_Enabled() {
TangemThemePreview {
PrimaryStartIconButton(
text = "Manage tokens",
iconResId = R.drawable.ic_tangem_24,
enabled = true,
onClick = {},
)
}
}
@Preview(widthDp = 328, heightDp = 48, showBackground = true)
@Preview(widthDp = 328, heightDp = 48, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun Preview_PrimaryStartIconButton_Disabled() {
TangemThemePreview {
PrimaryStartIconButton(
text = "Manage tokens",
iconResId = R.drawable.ic_tangem_24,
enabled = false,
onClick = {},
)
}
}
@Preview(widthDp = 328, heightDp = 48, showBackground = true)
@Preview(widthDp = 328, heightDp = 48, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun Preview_PrimaryEndIconButton_Enabled() {
TangemThemePreview {
PrimaryEndIconButton(
text = "Manage tokens",
iconResId = R.drawable.ic_tangem_24,
enabled = true,
onClick = {},
)
}
}
@Preview(widthDp = 328, heightDp = 48, showBackground = true)
@Preview(widthDp = 328, heightDp = 48, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun Preview_PrimaryEndIconButton_Disabled() {
TangemThemePreview {
PrimaryEndIconButton(
text = "Manage tokens",
iconResId = R.drawable.ic_tangem_24,
enabled = false,
onClick = {},
)
}
}
/**
* Primary button with an icon at the beginning of the layout
*
* @param modifier button modifier
* @param text button text
* @param iconResId button icon res id
* @param enabled controls the enabled state of the button
* @param onClick the lambda to be invoked when this button is pressed
*
* @see <a href = "https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?node-id=233%3A258&t=WdN5XpixzZLlQAZO-4"
* >Figma component</a>
*/
@Deprecated("Use PrimaryButtonIconRight instead")
@Composable
fun PrimaryStartIconButton(
text: String,
@DrawableRes iconResId: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
) {
PrimaryButtonRow(
modifier = modifier,
enabled = enabled,
onClick = onClick,
content = {
Icon(
painter = painterResource(id = iconResId),
contentDescription = null,
)
SpacerW8()
Text(text = text)
},
)
}
/**
* Primary button with an icon at the end of the layout
*
* @param modifier button modifier
* @param text button text
* @param iconResId button icon res id
* @param enabled controls the enabled state of the button
* @param onClick the lambda to be invoked when this button is pressed
*
* @see <a href = "https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?node-id=68%3A47&t=WdN5XpixzZLlQAZO-4"
* >Figma component</a>
*/
@Deprecated("Use PrimaryButtonIconLeft instead")
@Composable
fun PrimaryEndIconButton(
text: String,
@DrawableRes iconResId: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
) {
PrimaryButtonRow(
modifier = modifier,
enabled = enabled,
onClick = onClick,
content = {
Text(text = text)
SpacerW8()
Icon(
painter = painterResource(id = iconResId),
contentDescription = null,
)
},
)
}
@Composable
private fun PrimaryButtonRow(
enabled: Boolean,
onClick: () -> Unit,
content: @Composable (RowScope.() -> Unit),
modifier: Modifier = Modifier,
) {
Button(
onClick = onClick,
modifier = modifier
.fillMaxWidth()
.height(TangemTheme.dimens.size48),
enabled = enabled,
shape = RoundedCornerShape(TangemTheme.dimens.radius12),
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.colors.buttonColor(type = ButtonColorType.PRIMARY),
contentColor = MaterialTheme.colors.textColor(type = TextColorType.PRIMARY2),
disabledBackgroundColor = MaterialTheme.colors.buttonColor(type = ButtonColorType.DISABLED),
disabledContentColor = MaterialTheme.colors.textColor(type = TextColorType.DISABLED),
),
content = content,
)
}

View file

@ -1,24 +0,0 @@
package com.tangem.core.ui.res
import androidx.compose.material.Colors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.tangem.core.ui.res.TangemColorPalette.Dark5
import com.tangem.core.ui.res.TangemColorPalette.Dark6
import com.tangem.core.ui.res.TangemColorPalette.DarkGreen
import com.tangem.core.ui.res.TangemColorPalette.Light1
import com.tangem.core.ui.res.TangemColorPalette.Light2
import com.tangem.core.ui.res.TangemColorPalette.MagicMint
import com.tangem.core.ui.res.TangemColorPalette.Meadow
@Deprecated("Use TangemTheme.colors")
enum class ButtonColorType(val lightColor: Color, val darkColor: Color) {
PRIMARY(lightColor = Dark6, darkColor = Light1),
SECONDARY(lightColor = Light2, darkColor = Dark5),
DISABLED(lightColor = Light2, darkColor = Dark6),
POSITIVE(lightColor = Meadow, darkColor = Meadow),
POSITIVE_DISABLED(lightColor = MagicMint, darkColor = DarkGreen),
}
@Composable
fun Colors.buttonColor(type: ButtonColorType): Color = if (IS_SYSTEM_IN_DARK_THEME) type.darkColor else type.lightColor

View file

@ -1,32 +0,0 @@
package com.tangem.core.ui.res
import androidx.compose.material.Colors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.tangem.core.ui.res.TangemColorPalette.Amaranth
import com.tangem.core.ui.res.TangemColorPalette.Azure
import com.tangem.core.ui.res.TangemColorPalette.Black
import com.tangem.core.ui.res.TangemColorPalette.Dark1
import com.tangem.core.ui.res.TangemColorPalette.Dark2
import com.tangem.core.ui.res.TangemColorPalette.Dark4
import com.tangem.core.ui.res.TangemColorPalette.Dark6
import com.tangem.core.ui.res.TangemColorPalette.Light4
import com.tangem.core.ui.res.TangemColorPalette.Light5
import com.tangem.core.ui.res.TangemColorPalette.Mustard
import com.tangem.core.ui.res.TangemColorPalette.Tangerine
import com.tangem.core.ui.res.TangemColorPalette.White
@Deprecated("Use TangemTheme.colors")
enum class IconColorType(val lightColor: Color, val darkColor: Color) {
PRIMARY1(lightColor = Black, darkColor = White),
PRIMARY2(lightColor = White, darkColor = Dark6),
SECONDARY(lightColor = Dark2, darkColor = Dark1),
INFORMATIVE(lightColor = Light5, darkColor = Dark2),
INACTIVE(lightColor = Light4, darkColor = Dark4),
ACCENT(lightColor = Azure, darkColor = Azure),
WARNING(lightColor = Amaranth, darkColor = Amaranth),
ATTENTION(lightColor = Tangerine, darkColor = Mustard),
}
@Composable
fun Colors.iconColor(type: IconColorType): Color = if (IS_SYSTEM_IN_DARK_THEME) type.darkColor else type.lightColor

View file

@ -1,32 +0,0 @@
package com.tangem.core.ui.res
import androidx.compose.material.Colors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.tangem.core.ui.res.TangemColorPalette.Amaranth
import com.tangem.core.ui.res.TangemColorPalette.Dark1
import com.tangem.core.ui.res.TangemColorPalette.Dark2
import com.tangem.core.ui.res.TangemColorPalette.Dark3
import com.tangem.core.ui.res.TangemColorPalette.Dark6
import com.tangem.core.ui.res.TangemColorPalette.Light4
import com.tangem.core.ui.res.TangemColorPalette.Light5
import com.tangem.core.ui.res.TangemColorPalette.Meadow
import com.tangem.core.ui.res.TangemColorPalette.Mustard
import com.tangem.core.ui.res.TangemColorPalette.Tangerine
import com.tangem.core.ui.res.TangemColorPalette.White
@Deprecated("Use TangemTheme.colors")
enum class TextColorType(val lightColor: Color, val darkColor: Color) {
PRIMARY1(lightColor = Dark6, darkColor = White),
PRIMARY2(lightColor = White, darkColor = Dark6),
SECONDARY(lightColor = Dark2, darkColor = Light5),
TERTIARY(lightColor = Dark1, darkColor = Dark1),
DISABLED(lightColor = Light4, darkColor = Dark3),
ACCENT(lightColor = Meadow, darkColor = Meadow),
WARNING(lightColor = Amaranth, darkColor = Amaranth),
ATTENTION(lightColor = Tangerine, darkColor = Mustard),
CONSTANT_WHITE(lightColor = White, darkColor = White),
}
@Composable
fun Colors.textColor(type: TextColorType): Color = if (IS_SYSTEM_IN_DARK_THEME) type.darkColor else type.lightColor

View file

@ -3,14 +3,15 @@ package com.tangem.feature.referral.ui
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.tangem.core.ui.components.PrimaryEndIconButton
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.core.ui.components.PrimaryButtonIconEnd
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.feature.referral.presentation.R
@Composable
@ -20,11 +21,14 @@ internal fun NonParticipateBottomBlock(onAgreementClick: () -> Unit, onParticipa
firstPartResId = R.string.referral_tos_not_enroled_prefix,
onClick = onAgreementClick,
)
PrimaryEndIconButton(
modifier = Modifier.padding(all = TangemTheme.dimens.spacing16),
PrimaryButtonIconEnd(
text = stringResource(id = R.string.referral_button_participate),
iconResId = R.drawable.ic_tangem_24,
onClick = onParticipateClick,
modifier = Modifier
.fillMaxWidth()
.padding(all = TangemTheme.dimens.spacing16),
)
}
}

View file

@ -25,7 +25,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import androidx.core.content.ContextCompat.startActivity
import com.tangem.core.ui.components.PrimaryStartIconButton
import com.tangem.core.ui.components.PrimaryButtonIconStart
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.feature.referral.domain.models.ExpectedAward
@ -281,8 +281,7 @@ private fun AdditionalButtons(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16),
) {
PrimaryStartIconButton(
modifier = Modifier.weight(1f),
PrimaryButtonIconStart(
text = stringResource(id = R.string.common_copy),
iconResId = R.drawable.ic_copy_24,
onClick = {
@ -297,11 +296,11 @@ private fun AdditionalButtons(
)
}
},
modifier = Modifier.weight(1f),
)
val context = LocalContext.current
PrimaryStartIconButton(
modifier = Modifier.weight(1f),
PrimaryButtonIconStart(
text = stringResource(id = R.string.common_share),
iconResId = R.drawable.ic_share_24,
onClick = {
@ -309,6 +308,7 @@ private fun AdditionalButtons(
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
context.shareText(context.getString(R.string.referral_share_link, shareLink))
},
modifier = Modifier.weight(1f),
)
}
}