Decrease keyboard button animation duration

closes #162
This commit is contained in:
Sad Ellie 2024-01-18 14:00:21 +03:00
parent bb0b75e3f4
commit f413e98d27
2 changed files with 9 additions and 5 deletions

View File

@ -19,6 +19,7 @@
package com.sadellie.unitto.core.ui.common package com.sadellie.unitto.core.ui.common
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@ -65,6 +66,7 @@ fun BasicKeyboardButton(
onLongClick = if (onLongClick != null) { { onLongClick(); vibrate() } } else null, onLongClick = if (onLongClick != null) { { onLongClick(); vibrate() } } else null,
interactionSource = remember { MutableInteractionSource() }, interactionSource = remember { MutableInteractionSource() },
cornerRadiusRange = 30..50, cornerRadiusRange = 30..50,
animationSpec = tween(250)
) )
.background(containerColor) .background(containerColor)
, ,

View File

@ -18,7 +18,7 @@
package com.sadellie.unitto.core.ui.common package com.sadellie.unitto.core.ui.common
import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateIntAsState import androidx.compose.animation.core.animateIntAsState
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
@ -41,15 +41,16 @@ fun Modifier.squashable(
interactionSource: MutableInteractionSource, interactionSource: MutableInteractionSource,
cornerRadiusRange: IntRange, cornerRadiusRange: IntRange,
role: Role = Role.Button, role: Role = Role.Button,
animationSpec: AnimationSpec<Int> = tween(),
) = composed { ) = composed {
val isPressed by interactionSource.collectIsPressedAsState() val isPressed by interactionSource.collectIsPressedAsState()
val cornerRadius: Int by animateIntAsState( val cornerRadius: Int by animateIntAsState(
targetValue = if (isPressed) cornerRadiusRange.first else cornerRadiusRange.last, targetValue = if (isPressed) cornerRadiusRange.first else cornerRadiusRange.last,
animationSpec = tween(easing = FastOutSlowInEasing), animationSpec = animationSpec,
label = "Squashed animation" label = "Squashed animation"
) )
Modifier this
.clip(RoundedCornerShape(cornerRadius)) .clip(RoundedCornerShape(cornerRadius))
.combinedClickable( .combinedClickable(
onClick = onClick, onClick = onClick,
@ -68,15 +69,16 @@ fun Modifier.squashable(
interactionSource: MutableInteractionSource, interactionSource: MutableInteractionSource,
cornerRadiusRange: ClosedRange<Dp>, cornerRadiusRange: ClosedRange<Dp>,
role: Role = Role.Button, role: Role = Role.Button,
animationSpec: AnimationSpec<Dp> = tween(),
) = composed { ) = composed {
val isPressed by interactionSource.collectIsPressedAsState() val isPressed by interactionSource.collectIsPressedAsState()
val cornerRadius: Dp by animateDpAsState( val cornerRadius: Dp by animateDpAsState(
targetValue = if (isPressed) cornerRadiusRange.start else cornerRadiusRange.endInclusive, targetValue = if (isPressed) cornerRadiusRange.start else cornerRadiusRange.endInclusive,
animationSpec = tween(easing = FastOutSlowInEasing), animationSpec = animationSpec,
label = "Squashed animation" label = "Squashed animation"
) )
Modifier this
.clip(RoundedCornerShape(cornerRadius)) .clip(RoundedCornerShape(cornerRadius))
.combinedClickable( .combinedClickable(
onClick = onClick, onClick = onClick,