@@ -2,8 +2,13 @@ package to.bitkit.ui.shared.modifiers
22
33import androidx.compose.animation.core.Animatable
44import androidx.compose.foundation.gestures.detectTapGestures
5+ import androidx.compose.runtime.Composable
6+ import androidx.compose.runtime.remember
7+ import androidx.compose.runtime.rememberCoroutineScope
58import androidx.compose.ui.Modifier
9+ import androidx.compose.ui.graphics.graphicsLayer
610import androidx.compose.ui.input.pointer.SuspendingPointerInputModifierNode
11+ import androidx.compose.ui.input.pointer.pointerInput
712import androidx.compose.ui.layout.Measurable
813import androidx.compose.ui.layout.MeasureResult
914import androidx.compose.ui.layout.MeasureScope
@@ -101,3 +106,33 @@ private class ClickableAlphaNode(
101106 }
102107 }
103108}
109+
110+ /* *
111+ * Applies alpha animation feedback on press without consuming click events.
112+ * This allows the Button's onClick to work while providing full-area visual feedback.
113+ */
114+ @Composable
115+ fun Modifier.alphaFeedback (
116+ pressedAlpha : Float = 0.7f,
117+ enabled : Boolean = true,
118+ ): Modifier = if (enabled) {
119+ val animatable = remember { Animatable (1f ) }
120+ val scope = rememberCoroutineScope()
121+
122+ this
123+ .pointerInput(Unit ) {
124+ detectTapGestures(
125+ onPress = {
126+ scope.launch { animatable.animateTo(pressedAlpha) }
127+ tryAwaitRelease()
128+ scope.launch { animatable.animateTo(1f ) }
129+ },
130+ onTap = null // Don't consume tap - let Button handle it
131+ )
132+ }
133+ .graphicsLayer {
134+ alpha = animatable.value
135+ }
136+ } else {
137+ this
138+ }
0 commit comments