Updated on 2026-08-14

This commit is contained in:
Tangem 2023-01-20 18:52:52 +08:00
parent e6fcb9e2fe
commit 40c37826bf
198 changed files with 791 additions and 704 deletions

View file

@ -150,7 +150,9 @@ fun PrimaryStartIconButton(
enabled: Boolean = true,
) {
PrimaryButtonRow(
modifier = modifier, enabled = enabled, onClick = onClick,
modifier = modifier,
enabled = enabled,
onClick = onClick,
content = {
Icon(
painter = painterResource(id = iconResId),
@ -184,7 +186,9 @@ fun PrimaryEndIconButton(
enabled: Boolean = true,
) {
PrimaryButtonRow(
modifier = modifier, enabled = enabled, onClick = onClick,
modifier = modifier,
enabled = enabled,
onClick = onClick,
content = {
Text(text = text)
Spacer(modifier = Modifier.width(dimensionResource(R.dimen.spacing8)))

View file

@ -83,7 +83,6 @@ fun SmallInfoCardWithWarning(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
CardInfoBox(startText = startText, endText = endText)
Divider(
@ -195,7 +194,6 @@ fun IconWithTitleAndDescription(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
) {
Box(
modifier = Modifier
.background(

View file

@ -17,7 +17,6 @@ import com.tangem.core.ui.res.TangemTheme
@Composable
fun CurrencyPlaceholderIcon(id: String, modifier: Modifier = Modifier) {
val letterColor: Color = TangemTheme.colors.text.primary2
val circleColor: Color = TangemTheme.colors.icon.secondary
@ -25,8 +24,7 @@ fun CurrencyPlaceholderIcon(id: String, modifier: Modifier = Modifier) {
contentAlignment = Alignment.Center,
modifier = modifier
.background(circleColor, shape = CircleShape),
)
{
) {
Text(
text = id.firstOrNull()?.titlecase() ?: "",
textAlign = TextAlign.Center,

View file

@ -28,7 +28,6 @@ fun keyboardAsState(): State<Keyboard> {
}
DisposableEffect(view) {
val onGlobalListener = ViewTreeObserver.OnGlobalLayoutListener {
val rect = Rect()
view.getWindowVisibleDisplayFrame(rect)
val screenHeight = view.rootView.height

View file

@ -22,6 +22,7 @@ import androidx.compose.ui.unit.TextUnit
/**
* https://stackoverflow.com/questions/69083061/how-to-make-middle-ellipsis-in-text-with-jetpack-compose
*/
@Suppress("LongMethod")
@Composable
fun MiddleEllipsisText(
text: String,
@ -71,25 +72,28 @@ fun MiddleEllipsisText(
return@SubcomposeLayout layout(0, 0) {}
val placeable = subcompose("visible") {
val finalText = remember(text, textLayoutResult, constraints.maxWidth) {
if (text.isEmpty() || textLayoutResult.getBoundingBox(text.indices.last).right <= constraints.maxWidth) {
if (
text.isEmpty() ||
textLayoutResult.getBoundingBox(text.indices.last).right <= constraints.maxWidth
) {
// text not including ellipsis fits on the first line.
return@remember text
}
val ellipsisWidth = layoutText.indices.toList()
.takeLast(ellipsisCharactersCount)
.takeLast(ELLIPSIS_CHARACTERS_COUNT)
.let widthLet@{ indices ->
// fix this bug: https://issuetracker.google.com/issues/197146630
// in this case width is invalid
for (i in indices) {
val width = textLayoutResult.getBoundingBox(i).width
if (width > 0) {
return@widthLet width * ellipsisCharactersCount
return@widthLet width * ELLIPSIS_CHARACTERS_COUNT
}
}
// this should not happen, because
// this error occurs only for the last character in the string
throw IllegalStateException("all ellipsis chars have invalid width")
error("all ellipsis chars have invalid width")
}
val availableWidth = constraints.maxWidth - ellipsisWidth
val startCounter = BoundCounter(text, textLayoutResult) { it }
@ -98,8 +102,8 @@ fun MiddleEllipsisText(
while (availableWidth - startCounter.width - endCounter.width > 0) {
val possibleEndWidth = endCounter.widthWithNextChar()
if (
startCounter.width >= possibleEndWidth
&& availableWidth - startCounter.width - possibleEndWidth >= 0
startCounter.width >= possibleEndWidth &&
availableWidth - startCounter.width - possibleEndWidth >= 0
) {
endCounter.addNextChar()
} else if (availableWidth - startCounter.widthWithNextChar() - endCounter.width >= 0) {
@ -132,9 +136,9 @@ fun MiddleEllipsisText(
}
}
private const val ellipsisCharactersCount = 3
private const val ellipsisCharacter = '.'
private val ellipsisText = List(ellipsisCharactersCount) { ellipsisCharacter }.joinToString(separator = "")
private const val ELLIPSIS_CHARACTERS_COUNT = 3
private const val ELLIPSIS_CHARACTER = '.'
private val ellipsisText = List(ELLIPSIS_CHARACTERS_COUNT) { ELLIPSIS_CHARACTER }.joinToString(separator = "")
private class BoundCounter(
private val text: String,

View file

@ -47,15 +47,15 @@ import com.tangem.core.ui.res.TangemTheme
*/
@Composable
fun ResultScreenContent(
modifier: Modifier = Modifier,
resultMessage: AnnotatedString,
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
@StringRes title: Int = R.string.common_success,
resultColor: Color = TangemTheme.colors.icon.accent,
@DrawableRes icon: Int = R.drawable.ic_check_24,
@DrawableRes secondaryButtonIcon: Int? = null,
@StringRes secondaryButtonText: Int? = null,
onSecondaryButtonClick: (() -> Unit)? = null,
onButtonClick: () -> Unit,
) {
Column(
modifier = modifier
@ -93,8 +93,6 @@ fun ResultScreenContent(
secondaryButtonText = secondaryButtonText,
secondaryButtonIcon = secondaryButtonIcon,
onSecondaryButtonClick = onSecondaryButtonClick,
modifier = Modifier
.fillMaxWidth(),
)
SpacerH12()
}
@ -143,23 +141,22 @@ fun SuccessImage(
@Composable
private fun SecondaryButtonForResultScreen(
modifier: Modifier = Modifier,
@StringRes secondaryButtonText: Int,
onSecondaryButtonClick: () -> Unit,
@DrawableRes secondaryButtonIcon: Int? = null,
onSecondaryButtonClick: (() -> Unit),
) {
if (secondaryButtonIcon != null) {
SecondaryButtonIconLeft(
text = stringResource(id = secondaryButtonText),
icon = painterResource(id = secondaryButtonIcon),
onClick = onSecondaryButtonClick,
modifier = modifier,
modifier = Modifier.fillMaxWidth(),
)
} else {
SecondaryButton(
text = stringResource(id = secondaryButtonText),
onClick = onSecondaryButtonClick,
modifier = modifier,
modifier = Modifier.fillMaxWidth(),
)
}
}
@ -178,7 +175,7 @@ private fun SuccessScreenPreview() {
@Preview(showBackground = true)
@Composable
fun Preview_SuccessScreenContent_InLightTheme() {
private fun Preview_SuccessScreenContent_InLightTheme() {
TangemTheme(isDark = false) {
SuccessScreenPreview()
}
@ -186,7 +183,7 @@ fun Preview_SuccessScreenContent_InLightTheme() {
@Preview(showBackground = true)
@Composable
fun Preview_SuccessScreenContent_InDarkTheme() {
private fun Preview_SuccessScreenContent_InDarkTheme() {
TangemTheme(isDark = true) {
SuccessScreenPreview()
}

View file

@ -25,13 +25,11 @@ import com.tangem.core.ui.res.TangemTheme
*/
@Composable
fun WarningCard(
modifier: Modifier = Modifier,
title: String,
description: String,
icon: @Composable (() -> Unit)? = null,
) {
WarningCardSurface(
modifier = modifier,
content = {
WarningBody(
title = title,
@ -54,14 +52,12 @@ fun WarningCard(
*/
@Composable
fun ClickableWarningCard(
modifier: Modifier = Modifier,
title: String,
description: String,
icon: @Composable (() -> Unit)? = null,
onClick: () -> Unit,
) {
WarningCardSurface(
modifier = modifier,
content = {
WarningBody(title = title, description = description, icon = icon) {
SpacerW12()
@ -88,14 +84,12 @@ fun ClickableWarningCard(
*/
@Composable
fun RefreshableWaringCard(
modifier: Modifier = Modifier,
title: String,
description: String,
icon: @Composable (() -> Unit)? = null,
onClick: () -> Unit,
) {
WarningCardSurface(
modifier = modifier,
content = {
WarningBody(title = title, description = description, icon = icon) {
SpacerW12()
@ -114,7 +108,6 @@ fun RefreshableWaringCard(
@Composable
private fun WarningBody(
modifier: Modifier = Modifier,
title: String,
description: String,
icon: @Composable (() -> Unit)? = null,
@ -136,7 +129,6 @@ private fun WarningBody(
@OptIn(ExperimentalMaterialApi::class)
@Composable
private fun WarningCardSurface(
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
content: @Composable () -> Unit,
) {
@ -146,7 +138,6 @@ private fun WarningCardSurface(
elevation = TangemTheme.dimens.elevation2,
onClick = { onClick ?: Unit },
enabled = onClick != null,
modifier = modifier,
) {
content()
}

View file

@ -45,8 +45,8 @@ import com.tangem.core.ui.res.TangemTheme
* @param expandedInitially whether the search is expanded on launch
* @param tint tint for most of the visual elements of toolbar
* @param onBackClick action when close button is clicked
* @param onSearchChanged action when search is modified
* @param onSearchDisplayClosed action when search is closed
* @param onSearchChange action when search is modified
* @param onSearchDisplayClose action when search is closed
*
* @see <a href =
* "https://www.figma.com/file/Vs6SkVsFnUPsSCNwlnVf5U/Android-%E2%80%93-UI?node-id=1123%3A4068&t=xj8BBj5DfCWn2Mli-1"
@ -54,35 +54,30 @@ import com.tangem.core.ui.res.TangemTheme
*/
@Composable
fun ExpandableSearchView(
modifier: Modifier = Modifier,
onBackClick: () -> Unit,
onSearchChange: (String) -> Unit,
onSearchDisplayClose: () -> Unit,
title: String? = null,
placeholderSearchText: String = "",
expandedInitially: Boolean = false,
tint: Color = TangemTheme.colors.icon.primary1,
onBackClick: () -> Unit,
onSearchChanged: (String) -> Unit,
onSearchDisplayClosed: () -> Unit,
) {
val (expanded, onExpandedChanged) = remember {
mutableStateOf(expandedInitially)
}
val (expanded, onExpandedChanged) = remember { mutableStateOf(expandedInitially) }
Crossfade(targetState = expanded) { isSearchFieldVisible ->
if (isSearchFieldVisible) {
ExpandedSearchView(
placeholderSearchText = placeholderSearchText,
onSearchChanged = onSearchChanged,
onSearchDisplayClosed = onSearchDisplayClosed,
onExpandedChanged = onExpandedChanged,
modifier = modifier,
onSearchChange = onSearchChange,
onSearchDisplayClose = onSearchDisplayClose,
onExpandedChange = onExpandedChanged,
tint = tint,
)
} else {
CollapsedSearchView(
title = title,
onBackClick = onBackClick,
onExpandedChanged = onExpandedChanged,
modifier = modifier,
onExpandedChange = onExpandedChanged,
tint = tint,
)
}
@ -91,14 +86,13 @@ fun ExpandableSearchView(
@Composable
private fun CollapsedSearchView(
modifier: Modifier = Modifier,
title: String? = null,
onBackClick: () -> Unit,
onExpandedChanged: (Boolean) -> Unit,
tint: Color,
onBackClick: () -> Unit,
onExpandedChange: (Boolean) -> Unit,
title: String? = null,
) {
Row(
modifier = modifier
modifier = Modifier
.background(TangemTheme.colors.background.secondary)
.padding(TangemTheme.dimens.spacing16)
.fillMaxWidth(),
@ -127,7 +121,7 @@ private fun CollapsedSearchView(
tint = tint,
contentDescription = null,
modifier = Modifier
.clickable { onExpandedChanged(true) },
.clickable { onExpandedChange(true) },
)
}
}
@ -135,10 +129,9 @@ private fun CollapsedSearchView(
@Composable
private fun ExpandedSearchView(
placeholderSearchText: String,
onSearchChanged: (String) -> Unit,
onSearchDisplayClosed: () -> Unit,
onExpandedChanged: (Boolean) -> Unit,
modifier: Modifier = Modifier,
onSearchChange: (String) -> Unit,
onSearchDisplayClose: () -> Unit,
onExpandedChange: (Boolean) -> Unit,
tint: Color,
) {
val focusManager = LocalFocusManager.current
@ -151,7 +144,7 @@ private fun ExpandedSearchView(
var textFieldValue by remember { mutableStateOf(TextFieldValue("", TextRange("".length))) }
Row(
modifier = modifier
modifier = Modifier
.background(TangemTheme.colors.background.secondary)
.fillMaxWidth(),
horizontalArrangement = Arrangement.Start,
@ -159,8 +152,8 @@ private fun ExpandedSearchView(
) {
IconButton(
onClick = {
onExpandedChanged(false)
onSearchDisplayClosed()
onExpandedChange(false)
onSearchDisplayClose()
},
) {
Icon(
@ -173,7 +166,7 @@ private fun ExpandedSearchView(
value = textFieldValue,
onValueChange = {
textFieldValue = it
onSearchChanged(it.text)
onSearchChange(it.text)
},
singleLine = true,
modifier = Modifier
@ -205,8 +198,8 @@ private fun CollapsedSearchViewPreview() {
title = "Choose Token",
onBackClick = {},
placeholderSearchText = "Search",
onSearchChanged = {},
onSearchDisplayClosed = {},
onSearchChange = {},
onSearchDisplayClose = {},
)
}
}
@ -219,10 +212,9 @@ private fun ExpandedSearchViewPreview() {
title = "Choose Token",
onBackClick = {},
placeholderSearchText = "Search",
onSearchChanged = {},
onSearchChange = {},
expandedInitially = true,
onSearchDisplayClosed = {},
onSearchDisplayClose = {},
)
}
}
}

View file

@ -34,5 +34,4 @@ fun getActiveIconRes(blockchainId: String): Int {
"DASH" -> R.drawable.img_dash_22
else -> R.drawable.ic_alert_24
}
}
}