From 2a812a836ccd53eafea2d674242aa45a7c19c7d1 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 8 Aug 2022 16:54:14 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../details/ui/common/TangemSwitch.kt | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/common/TangemSwitch.kt b/app/src/main/java/com/tangem/tap/features/details/ui/common/TangemSwitch.kt index 3132bb6fcc..9eda9be886 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/common/TangemSwitch.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/common/TangemSwitch.kt @@ -6,7 +6,6 @@ import androidx.compose.animation.core.LinearOutSlowInEasing import androidx.compose.animation.core.animateDp import androidx.compose.animation.core.tween import androidx.compose.animation.core.updateTransition -import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.indication @@ -19,7 +18,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Card import androidx.compose.material.ripple.rememberRipple import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -44,30 +42,22 @@ fun TangemSwitch( val transition = updateTransition(checked, label = "SwitchState") val color by transition.animateColor( transitionSpec = { - tween(200, easing = FastOutLinearInEasing) + tween(durationMillis = 200, easing = FastOutLinearInEasing) }, label = "", - ) { - when (it) { - true -> enabledColor - false -> disabledColor - } + ) { enabled -> + if (enabled) enabledColor else disabledColor } val interactionSource = remember { MutableInteractionSource() } - val clickable = Modifier.clickable( - interactionSource = interactionSource, - indication = null, - ) { - if (!checked) { - onCheckedChange(true) - } else { - onCheckedChange(false) - } - } Box( - modifier = Modifier - .then(clickable) + modifier = modifier + .clickable( + interactionSource = interactionSource, + indication = null, + ) { + onCheckedChange(!checked) + } .indication( interactionSource = MutableInteractionSource(), indication = rememberRipple( @@ -88,27 +78,19 @@ fun TangemSwitch( val roundCardSize = this.maxWidth / 2 val xOffset by transition.animateDp( transitionSpec = { - tween(150, easing = LinearOutSlowInEasing) + tween(durationMillis = 150, easing = LinearOutSlowInEasing) }, label = "xOffset", - ) { state -> - when (state) { - false -> 0.dp - true -> this.maxWidth - roundCardSize - } + ) { enabled -> + if (enabled) this.maxWidth - roundCardSize else 0.dp } - Card( + Box( modifier = Modifier .size(this.maxWidth / 2) .offset(x = xOffset, y = 0.dp) - .padding(3.dp), - shape = RoundedCornerShape(100), - backgroundColor = Color.White, - border = BorderStroke( - if (!checked) 0.5.dp else 0.dp, - color = Color.LightGray, - ), + .padding(3.dp) + .background(color = Color.White, shape = RoundedCornerShape(100)), ) { } }