@@ -4,13 +4,17 @@ import androidx.compose.animation.core.animateFloatAsState
44import androidx.compose.foundation.clickable
55import androidx.compose.foundation.interaction.MutableInteractionSource
66import androidx.compose.foundation.interaction.collectIsPressedAsState
7+ import androidx.compose.foundation.selection.selectable
8+ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
9+ import androidx.compose.material3.MaterialTheme
710import androidx.compose.runtime.Composable
811import androidx.compose.runtime.getValue
912import androidx.compose.runtime.remember
1013import androidx.compose.ui.Modifier
1114import androidx.compose.ui.draw.alpha
1215import androidx.compose.ui.semantics.Role
1316
17+ @OptIn(ExperimentalMaterial3ExpressiveApi ::class )
1418@Composable
1519fun Modifier.alphaIndicationClickable (
1620 enabled : Boolean = true,
@@ -21,7 +25,11 @@ fun Modifier.alphaIndicationClickable(
2125): Modifier {
2226 val interactionSource = interactionSource ? : remember { MutableInteractionSource () }
2327 val isPressed by interactionSource.collectIsPressedAsState()
24- val animatedAlpha by animateFloatAsState(if (isPressed) .5f else 1f )
28+ val animatedAlpha by
29+ animateFloatAsState(
30+ if (isPressed) .5f else 1f ,
31+ animationSpec = MaterialTheme .motionScheme.fastEffectsSpec(),
32+ )
2533
2634 return clickable(
2735 enabled = enabled,
@@ -33,3 +41,31 @@ fun Modifier.alphaIndicationClickable(
3341 )
3442 .alpha(animatedAlpha)
3543}
44+
45+ @OptIn(ExperimentalMaterial3ExpressiveApi ::class )
46+ @Composable
47+ fun Modifier.alphaIndicationSelectable (
48+ selected : Boolean ,
49+ enabled : Boolean = true,
50+ role : Role ? = null,
51+ interactionSource : MutableInteractionSource ? = null,
52+ onClick : () -> Unit ,
53+ ): Modifier {
54+ val interactionSource = interactionSource ? : remember { MutableInteractionSource () }
55+ val isPressed by interactionSource.collectIsPressedAsState()
56+ val animatedAlpha by
57+ animateFloatAsState(
58+ if (isPressed) .5f else 1f ,
59+ animationSpec = MaterialTheme .motionScheme.fastEffectsSpec(),
60+ )
61+
62+ return selectable(
63+ selected = selected,
64+ enabled = enabled,
65+ role = role,
66+ indication = null ,
67+ interactionSource = interactionSource,
68+ onClick = onClick,
69+ )
70+ .alpha(animatedAlpha)
71+ }
0 commit comments