Updated on 2026-08-14
This commit is contained in:
parent
b5209c613d
commit
6afbb27b6b
1 changed files with 24 additions and 20 deletions
|
|
@ -11,9 +11,11 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.draw.shadow
|
import androidx.compose.ui.draw.shadow
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.Density
|
||||||
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.components.SpacerW
|
import com.tangem.core.ui.components.SpacerW
|
||||||
|
|
@ -37,6 +39,10 @@ import com.tangem.core.ui.res.TangemThemePreviewRedesign
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
@Composable
|
@Composable
|
||||||
fun TangemTopSnackbar(snackbarMessage: SnackbarMessage, modifier: Modifier = Modifier) {
|
fun TangemTopSnackbar(snackbarMessage: SnackbarMessage, modifier: Modifier = Modifier) {
|
||||||
|
val density = LocalDensity.current
|
||||||
|
val fixedFontScaleDensity = remember(density) {
|
||||||
|
Density(density = density.density, fontScale = 1f)
|
||||||
|
}
|
||||||
val actionLabel = snackbarMessage.actionLabel
|
val actionLabel = snackbarMessage.actionLabel
|
||||||
val action = snackbarMessage.action
|
val action = snackbarMessage.action
|
||||||
val hasAction = actionLabel != null && action != null
|
val hasAction = actionLabel != null && action != null
|
||||||
|
|
@ -46,12 +52,7 @@ fun TangemTopSnackbar(snackbarMessage: SnackbarMessage, modifier: Modifier = Mod
|
||||||
snackbarMessage.startIconId,
|
snackbarMessage.startIconId,
|
||||||
hasAction,
|
hasAction,
|
||||||
) { mutableStateOf(false) }
|
) { mutableStateOf(false) }
|
||||||
val shape = if (isTextOverflowing) {
|
val shape = RoundedCornerShape(24.dp)
|
||||||
RoundedCornerShape(TangemTheme.dimens2.x5)
|
|
||||||
} else {
|
|
||||||
TangemTheme.shapes.roundedCornersXLarge
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.shadow(elevation = TangemTheme.dimens.elevation4, shape = shape, clip = false)
|
.shadow(elevation = TangemTheme.dimens.elevation4, shape = shape, clip = false)
|
||||||
|
|
@ -59,8 +60,8 @@ fun TangemTopSnackbar(snackbarMessage: SnackbarMessage, modifier: Modifier = Mod
|
||||||
.clip(shape)
|
.clip(shape)
|
||||||
.hazeEffectTangem()
|
.hazeEffectTangem()
|
||||||
.sizeIn(minHeight = TangemTheme.dimens2.x11)
|
.sizeIn(minHeight = TangemTheme.dimens2.x11)
|
||||||
.padding(start = TangemTheme.dimens2.x5, end = TangemTheme.dimens2.x3)
|
.padding(start = TangemTheme.dimens2.x4, end = TangemTheme.dimens2.x3)
|
||||||
.padding(vertical = TangemTheme.dimens2.x1),
|
.padding(vertical = TangemTheme.dimens2.x2),
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
|
|
@ -78,18 +79,20 @@ fun TangemTopSnackbar(snackbarMessage: SnackbarMessage, modifier: Modifier = Mod
|
||||||
SpacerW(TangemTheme.dimens2.x2)
|
SpacerW(TangemTheme.dimens2.x2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompositionLocalProvider(LocalDensity provides fixedFontScaleDensity) {
|
||||||
Text(
|
Text(
|
||||||
text = snackbarMessage.message.resolveReference(),
|
text = snackbarMessage.message.resolveReference(),
|
||||||
modifier = Modifier.weight(1f, fill = false),
|
modifier = Modifier.weight(1f, fill = false),
|
||||||
color = TangemTheme.colors.text.secondary,
|
color = TangemTheme.colors2.text.neutral.secondary,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 1,
|
maxLines = 2,
|
||||||
style = TangemTheme.typography.body2,
|
style = TangemTheme.typography2.captionMedium13,
|
||||||
onTextLayout = { layoutResult ->
|
onTextLayout = { layoutResult ->
|
||||||
val isOverflowing = hasAction && layoutResult.hasVisualOverflow
|
val isOverflowing = hasAction && layoutResult.hasVisualOverflow
|
||||||
if (isTextOverflowing != isOverflowing) isTextOverflowing = isOverflowing
|
if (isTextOverflowing != isOverflowing) isTextOverflowing = isOverflowing
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
SpacerW(TangemTheme.dimens2.x4)
|
SpacerW(TangemTheme.dimens2.x4)
|
||||||
|
|
||||||
|
|
@ -177,6 +180,7 @@ private fun Preview_TangemTopSnackbar_NoAction() {
|
||||||
)
|
)
|
||||||
TangemTopSnackbar(
|
TangemTopSnackbar(
|
||||||
snackbarMessage = SnackbarMessage(
|
snackbarMessage = SnackbarMessage(
|
||||||
|
startIconId = R.drawable.ic_eye_off_outline_24,
|
||||||
message = stringReference(
|
message = stringReference(
|
||||||
"Operation completed long long text that should be truncated with ellipsis at the end",
|
"Operation completed long long text that should be truncated with ellipsis at the end",
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue