This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private object NoRippleTheme : RippleTheme { | |
@Composable | |
override fun defaultColor() = // Ripple color | |
@Composable | |
override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f, 0.0f, 0.0f, 0.0f) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun NoRippleEffect2() { | |
Box( | |
modifier = Modifier | |
.height(height = 38.dp) | |
.background( | |
color = pink, | |
shape = RoundedCornerShape(percent = 12) | |
) | |
.clickable( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun NoRippleEffect1() { | |
Button( | |
onClick = { | |
//Clicked | |
}, | |
interactionSource = remember { NoRippleInteractionSource() }, | |
shape = RoundedCornerShape(12.dp), | |
contentPadding = PaddingValues(16.dp), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NoRippleInteractionSource : MutableInteractionSource { | |
override val interactions: Flow<Interaction> = emptyFlow() | |
override suspend fun emit(interaction: Interaction) {} | |
override fun tryEmit(interaction: Interaction) = true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Box( | |
modifier = Modifier | |
.background(color = pink, RoundedCornerShape(cornerRadius)) | |
.size(100.dp) | |
.clip(RoundedCornerShape(cornerRadius)) | |
.clickable( | |
interactionSource = interactionSource, | |
indication = rememberRipple() | |
) { | |
//Clicked |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val interactionSource = remember { MutableInteractionSource() } | |
val isPressed = interactionSource.collectIsPressedAsState() | |
val cornerRadius by animateDpAsState(targetValue = if (isPressed.value) 10.dp else 50.dp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ShakeEffect(){ | |
Button(onClick = { | |
//Clicked | |
}, shape = RoundedCornerShape(12.dp), contentPadding = PaddingValues(16.dp), | |
modifier = Modifier.shakeClickEffect()) { | |
Text(text = "Click me") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Modifier.shakeClickEffect() = composed { | |
var buttonState by remember { mutableStateOf(ButtonState.Idle) } | |
val tx by animateFloatAsState( | |
targetValue = if (buttonState == ButtonState.Pressed) 0f else -50f, | |
animationSpec = repeatable( | |
iterations = 2, | |
animation = tween(durationMillis = 50, easing = LinearEasing), | |
repeatMode = RepeatMode.Reverse | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun PressEffect() { | |
Button(onClick = { | |
//Clicked | |
}, shape = RoundedCornerShape(12.dp), contentPadding = PaddingValues(16.dp), | |
modifier = Modifier.pressClickEffect()) { | |
Text(text = "Click me") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class ButtonState { Pressed, Idle } | |
fun Modifier.pressClickEffect() = composed { | |
var buttonState by remember { mutableStateOf(ButtonState.Idle) } | |
val ty by animateFloatAsState(if (buttonState == ButtonState.Pressed) 0f else -20f) | |
this | |
.graphicsLayer { | |
translationY = ty | |
} | |
.clickable( |