Updated on 2026-08-14
This commit is contained in:
parent
ed70baecc4
commit
269e986601
2 changed files with 70 additions and 34 deletions
|
|
@ -3,19 +3,22 @@ package com.tangem.core.ui.ds.button.action
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.key
|
import androidx.compose.runtime.key
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.layout.Layout
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.semantics.disabled
|
import androidx.compose.ui.semantics.disabled
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.tangem.core.ui.R
|
import com.tangem.core.ui.R
|
||||||
import com.tangem.core.ui.ds.button.SecondaryTangemButton
|
import com.tangem.core.ui.ds.button.SecondaryTangemButton
|
||||||
|
|
@ -32,6 +35,8 @@ import com.tangem.core.ui.test.BaseActionButtonsBlockTestTags
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
|
|
||||||
|
private val ACTION_BUTTONS_SPACING = 10.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action buttons row
|
* Action buttons row
|
||||||
*
|
*
|
||||||
|
|
@ -42,42 +47,73 @@ import kotlinx.collections.immutable.persistentListOf
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun ActionButtons(buttons: ImmutableList<TangemButtonUM>, modifier: Modifier = Modifier) {
|
fun ActionButtons(buttons: ImmutableList<TangemButtonUM>, modifier: Modifier = Modifier) {
|
||||||
Row(
|
val spacingPx = with(LocalDensity.current) { ACTION_BUTTONS_SPACING.roundToPx() }
|
||||||
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
Layout(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
) {
|
content = {
|
||||||
buttons.forEachIndexed { index, button ->
|
buttons.forEachIndexed { index, button ->
|
||||||
key(button.text to index) {
|
key(button.text to index) {
|
||||||
val textColor = if (button.isEnabled) {
|
ActionButton(button = button)
|
||||||
TangemTheme.colors2.text.neutral.primary
|
|
||||||
} else {
|
|
||||||
TangemTheme.colors2.text.status.disabled
|
|
||||||
}
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(horizontal = TangemTheme.dimens2.x2_5)
|
|
||||||
.testTag(BaseActionButtonsBlockTestTags.ACTION_BUTTON)
|
|
||||||
.semantics { if (!button.isEnabled) disabled() },
|
|
||||||
verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens2.x2),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
) {
|
|
||||||
SecondaryTangemButton(
|
|
||||||
tangemIconUM = button.tangemIconUM,
|
|
||||||
onClick = button.onClick,
|
|
||||||
isEnabled = button.isEnabled,
|
|
||||||
shape = TangemButtonShape.Rounded,
|
|
||||||
onLongClick = button.onLongClick,
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = button.text.orEmpty().resolveReference(),
|
|
||||||
style = TangemTheme.typography2.subheadlineMedium14,
|
|
||||||
color = textColor,
|
|
||||||
maxLines = 1,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
) { measurables, constraints ->
|
||||||
|
if (measurables.isEmpty()) {
|
||||||
|
return@Layout layout(constraints.minWidth, constraints.minHeight) {}
|
||||||
}
|
}
|
||||||
|
val cellWidth = measurables.maxOf { it.maxIntrinsicWidth(constraints.maxHeight) }
|
||||||
|
val cellConstraints = Constraints(
|
||||||
|
minWidth = cellWidth,
|
||||||
|
maxWidth = cellWidth,
|
||||||
|
minHeight = 0,
|
||||||
|
maxHeight = constraints.maxHeight,
|
||||||
|
)
|
||||||
|
val placeables = measurables.map { it.measure(cellConstraints) }
|
||||||
|
|
||||||
|
val contentWidth = cellWidth * placeables.size + spacingPx * (placeables.size - 1)
|
||||||
|
val width = if (constraints.hasBoundedWidth) maxOf(constraints.maxWidth, contentWidth) else contentWidth
|
||||||
|
val height = placeables.maxOf { it.height }
|
||||||
|
|
||||||
|
layout(width, height) {
|
||||||
|
var x = (width - contentWidth) / 2
|
||||||
|
placeables.forEach { placeable ->
|
||||||
|
placeable.place(x = x, y = (height - placeable.height) / 2)
|
||||||
|
x += cellWidth + spacingPx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ActionButton(button: TangemButtonUM, modifier: Modifier = Modifier) {
|
||||||
|
val textColor = if (button.isEnabled) {
|
||||||
|
TangemTheme.colors2.text.neutral.primary
|
||||||
|
} else {
|
||||||
|
TangemTheme.colors2.text.status.disabled
|
||||||
|
}
|
||||||
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.padding(horizontal = TangemTheme.dimens2.x2_5)
|
||||||
|
.testTag(BaseActionButtonsBlockTestTags.ACTION_BUTTON)
|
||||||
|
.semantics { if (!button.isEnabled) disabled() },
|
||||||
|
verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens2.x2),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
) {
|
||||||
|
SecondaryTangemButton(
|
||||||
|
tangemIconUM = button.tangemIconUM,
|
||||||
|
onClick = button.onClick,
|
||||||
|
isEnabled = button.isEnabled,
|
||||||
|
shape = TangemButtonShape.Rounded,
|
||||||
|
onLongClick = button.onLongClick,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = button.text.orEmpty().resolveReference(),
|
||||||
|
style = TangemTheme.typography2.subheadlineMedium14,
|
||||||
|
color = textColor,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ internal fun WalletBalance(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SpacerH(TangemTheme.dimens2.x2)
|
SpacerH(TangemTheme.dimens2.x2)
|
||||||
ActionButtons(buttons)
|
ActionButtons(buttons, modifier = Modifier.fillMaxWidth())
|
||||||
SpacerH(TangemTheme.dimens2.x6)
|
SpacerH(TangemTheme.dimens2.x6)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue