Skip to content

Commit d11dc6d

Browse files
committed
ui: Add alpha transitions on press
1 parent d651dac commit d11dc6d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/src/main/java/to/bitkit/ui/shared/util/Modifiers.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package to.bitkit.ui.shared.util
22

3+
import androidx.compose.animation.core.animateFloatAsState
34
import androidx.compose.foundation.background
45
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.interaction.MutableInteractionSource
@@ -24,9 +25,10 @@ fun Modifier.clickableAlpha(
2425
): Modifier = composed {
2526
val interactionSource = remember { MutableInteractionSource() }
2627
val isPressed by interactionSource.collectIsPressedAsState()
28+
val alpha by animateFloatAsState(targetValue = if (isPressed) 0.7f else 1f)
2729

2830
this
29-
.graphicsLayer { this.alpha = if (isPressed) 0.7f else 1f }
31+
.graphicsLayer { this.alpha = alpha }
3032
.clickable(
3133
enabled = onClick != null,
3234
onClick = { onClick?.invoke() },
@@ -35,7 +37,6 @@ fun Modifier.clickableAlpha(
3537
)
3638
}
3739

38-
3940
fun Modifier.gradientBackground(): Modifier {
4041
return this.background(
4142
brush = Brush.verticalGradient(

0 commit comments

Comments
 (0)