From 7480191e9ca5d018f15631658ad87eb9e1381ef3 Mon Sep 17 00:00:00 2001 From: kosenda Date: Fri, 6 Sep 2024 01:23:45 +0900 Subject: [PATCH] feature: add interactionSource --- .../about/component/AboutFooterLinksIcon.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/feature/about/src/commonMain/kotlin/io/github/droidkaigi/confsched/about/component/AboutFooterLinksIcon.kt b/feature/about/src/commonMain/kotlin/io/github/droidkaigi/confsched/about/component/AboutFooterLinksIcon.kt index 39368f1f8..fb6fde48e 100644 --- a/feature/about/src/commonMain/kotlin/io/github/droidkaigi/confsched/about/component/AboutFooterLinksIcon.kt +++ b/feature/about/src/commonMain/kotlin/io/github/droidkaigi/confsched/about/component/AboutFooterLinksIcon.kt @@ -1,11 +1,21 @@ package io.github.droidkaigi.confsched.about.component +import androidx.compose.animation.core.Animatable import androidx.compose.foundation.Image +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.PressInteraction.Cancel +import androidx.compose.foundation.interaction.PressInteraction.Press +import androidx.compose.foundation.interaction.PressInteraction.Release import androidx.compose.foundation.layout.size import androidx.compose.material3.IconButton import androidx.compose.material3.Surface import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.scale import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp @@ -23,9 +33,22 @@ fun AboutFooterLinksIcon( modifier: Modifier = Modifier, onClick: () -> Unit, ) { + val animationScale by remember { mutableStateOf(Animatable(1f)) } + + val interactionSource = remember { MutableInteractionSource() } + LaunchedEffect(interactionSource) { + interactionSource.interactions.collect { + when (it) { + is Press -> animationScale.animateTo(targetValue = 0.9f) + is Release, is Cancel -> animationScale.animateTo(targetValue = 1.0f) + } + } + } + IconButton( onClick = onClick, - modifier = modifier.testTag(testTag), + interactionSource = interactionSource, + modifier = modifier.testTag(testTag).scale(animationScale.value), ) { Image( painter = painter,