From 31f4903d4805ff8352cfcf43497aa26789948f6d Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Sat, 28 Jan 2023 18:10:32 +0400 Subject: [PATCH] Added vibration on keyboard button press (#16) --- .../unitto/feature/converter/components/KeyboardButton.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/feature/converter/src/main/java/com/sadellie/unitto/feature/converter/components/KeyboardButton.kt b/feature/converter/src/main/java/com/sadellie/unitto/feature/converter/components/KeyboardButton.kt index 0bfbb828..55109b0c 100644 --- a/feature/converter/src/main/java/com/sadellie/unitto/feature/converter/components/KeyboardButton.kt +++ b/feature/converter/src/main/java/com/sadellie/unitto/feature/converter/components/KeyboardButton.kt @@ -18,6 +18,7 @@ package com.sadellie.unitto.feature.converter.components +import android.view.HapticFeedbackConstants import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.animateIntAsState import androidx.compose.animation.core.tween @@ -29,9 +30,11 @@ import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalView import androidx.compose.ui.unit.dp import com.sadellie.unitto.core.ui.common.UnittoButton import com.sadellie.unitto.core.ui.theme.NumbersTextStyleTitleLarge @@ -54,6 +57,7 @@ internal fun KeyboardButton( onLongClick: (() -> Unit)? = null, onClick: (String) -> Unit = {} ) { + val view = LocalView.current val interactionSource = remember { MutableInteractionSource() } val isPressed by interactionSource.collectIsPressedAsState() val cornerRadius: Int by animateIntAsState( @@ -77,4 +81,8 @@ internal fun KeyboardButton( color = if (isPrimary) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSecondaryContainer ) } + + LaunchedEffect(key1 = isPressed) { + if (isPressed) view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) + } }