mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Add missing long press haptic feedback to composables.
As recommended by https://developer.android.com/develop/ui/compose/touch-input/pointer-input/tap-and-press > As a best practice, you should include haptic feedback when the user long-presses elements.
This commit is contained in:
committed by
Cody Henthorne
parent
c89fbbe49f
commit
fe853f7b65
@@ -39,6 +39,8 @@ import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
@@ -300,13 +302,19 @@ object Rows {
|
||||
onLongClick: (() -> Unit)? = null,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.combinedClickable(
|
||||
enabled = enabled && (onClick != null || onLongClick != null),
|
||||
onClick = onClick ?: {},
|
||||
onLongClick = onLongClick ?: {}
|
||||
onLongClick = {
|
||||
if (onLongClick != null) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onLongClick()
|
||||
}
|
||||
}
|
||||
)
|
||||
.padding(defaultPadding()),
|
||||
verticalAlignment = CenterVertically
|
||||
|
||||
Reference in New Issue
Block a user