Fix wrong selection behaviour

This commit is contained in:
Jorge Martín
2026-06-23 17:14:08 +02:00
parent b3b8467636
commit 2902549a88
@@ -110,8 +110,27 @@ fun EmojiItem(
.background(backgroundColor, CircleShape) .background(backgroundColor, CircleShape)
.indication(interactionSource, ripple()) .indication(interactionSource, ripple())
.pointerInput(item) { .pointerInput(item) {
// Always detect long press and tap gestures
detectTapGestures(
onPress = { pressOffset ->
val press = PressInteraction.Press(pressOffset)
interactionSource.emit(press)
if (tryAwaitRelease()) {
interactionSource.emit(PressInteraction.Release(press))
if (hasSkinTones) {
onSelectEmoji(item)
}
} else {
interactionSource.emit(PressInteraction.Cancel(press))
}
},
onTap = { onSelectEmoji(item) },
)
}
.then(
// Only detect drag after long press for those items which have a skin tone picker // Only detect drag after long press for those items which have a skin tone picker
if (hasSkinTones) { if (hasSkinTones) {
Modifier.pointerInput(item) {
val slotWidthPx = with(density) { SkinToneSlotSize.toPx() } val slotWidthPx = with(density) { SkinToneSlotSize.toPx() }
val spacingPx = with(density) { SkinToneSlotSpacing.toPx() } val spacingPx = with(density) { SkinToneSlotSpacing.toPx() }
val paddingPx = with(density) { SkinTonePadding.toPx() } val paddingPx = with(density) { SkinTonePadding.toPx() }
@@ -186,21 +205,10 @@ fun EmojiItem(
}, },
) )
} }
// Always detect long press and tap gestures
detectTapGestures(
onPress = { pressOffset ->
val press = PressInteraction.Press(pressOffset)
interactionSource.emit(press)
if (tryAwaitRelease()) {
interactionSource.emit(PressInteraction.Release(press))
} else { } else {
interactionSource.emit(PressInteraction.Cancel(press)) Modifier
} }
},
onTap = { onSelectEmoji(item) },
) )
}
.clearAndSetSemantics { .clearAndSetSemantics {
contentDescription = description contentDescription = description
}, },