Skip to content

Commit

Permalink
feat(haptic): tweak haptic feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
outadoc committed Oct 4, 2024
1 parent ea49c16 commit 08dc884
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextRange
Expand Down Expand Up @@ -131,7 +129,6 @@ internal fun ChannelChatScreenContent(
},
content = { insets ->
val clipboard = LocalClipboardManager.current
val haptic = LocalHapticFeedback.current
val scope = rememberCoroutineScope()
val snackbarCopiedMessage = stringResource(MR.strings.chat_copiedToClipboard)

Expand All @@ -146,9 +143,6 @@ internal fun ChannelChatScreenContent(
// Copy to clipboard
clipboard.setText(AnnotatedString(rawMessage))

// Vibrate device
haptic.performHapticFeedback(HapticFeedbackType.LongPress)

// Show "copied to clipboard" confirmation
scope.launch {
snackbarHostState.showSnackbar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.semantics
Expand Down Expand Up @@ -68,6 +70,8 @@ internal fun ChatList(
insets: PaddingValues,
clock: Clock = Clock.System,
) {
val haptic = LocalHapticFeedback.current

val inlinesEmotes: PersistentMap<String, InlineTextContent> =
remember(emotes) {
emotes.mapValues { (_, emote) ->
Expand Down Expand Up @@ -175,7 +179,10 @@ internal fun ChatList(
.fillMaxWidth()
.combinedClickable(
onClick = {},
onLongClick = { onMessageLongClick(item) },
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
onMessageLongClick(item)
},
onLongClickLabel = stringResource(MR.strings.chat_copyToClipboard),
)
.semantics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
import fr.outadoc.justchatting.feature.chat.presentation.mobile.BasicUserInfo
Expand All @@ -40,6 +42,7 @@ internal fun FutureTimelineSegment(
segment: ChannelScheduleSegment,
onUserClick: () -> Unit = {},
) {
val haptic = LocalHapticFeedback.current
var isExpanded by remember { mutableStateOf(false) }

OutlinedCard(
Expand All @@ -50,7 +53,10 @@ internal fun FutureTimelineSegment(
modifier = Modifier
.combinedClickable(
onClick = { isExpanded = true },
onLongClick = { isExpanded = true },
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
isExpanded = true
},
),
) {
TimelineSegmentContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
Expand Down Expand Up @@ -53,6 +55,8 @@ internal fun LiveStreamCard(
onClick: () -> Unit = {},
onLongClick: () -> Unit = {},
) {
val haptic = LocalHapticFeedback.current

OutlinedCard(
modifier = modifier,
) {
Expand All @@ -62,7 +66,10 @@ internal fun LiveStreamCard(
.combinedClickable(
onClick = onClick,
onClickLabel = stringResource(MR.strings.chat_open_action),
onLongClick = onLongClick,
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
onLongClick()
},
onLongClickLabel = stringResource(MR.strings.all_showDetails_cd),
),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import fr.outadoc.justchatting.feature.timeline.domain.model.UserStream

@Composable
Expand All @@ -16,6 +18,7 @@ internal fun LiveTimelineSegment(
onOpenChat: () -> Unit = {},
onOpenInBubble: () -> Unit = {},
) {
val haptic = LocalHapticFeedback.current
var isExpanded by remember { mutableStateOf(false) }

LiveStreamCard(
Expand All @@ -30,6 +33,7 @@ internal fun LiveTimelineSegment(
onUserClick = onUserClick,
onClick = onOpenChat,
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
isExpanded = true
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
Expand All @@ -45,7 +47,9 @@ internal fun PastTimelineSegment(
segment: ChannelScheduleSegment,
onUserClick: () -> Unit = {},
) {
val haptic = LocalHapticFeedback.current
val uriHandler = LocalUriHandler.current

var isExpanded by remember { mutableStateOf(false) }

OutlinedCard(
Expand All @@ -61,7 +65,10 @@ internal fun PastTimelineSegment(
)
},
onClickLabel = stringResource(MR.strings.timeline_openVod_action),
onLongClick = { isExpanded = true },
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
isExpanded = true
},
onLongClickLabel = stringResource(MR.strings.all_showDetails_cd),
),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import androidx.compose.material3.TooltipDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
Expand All @@ -30,8 +28,6 @@ internal fun AccessibleIconButton(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable () -> Unit,
) {
val haptic = LocalHapticFeedback.current

val tooltipPosition = TooltipDefaults.rememberPlainTooltipPositionProvider()
val tooltipState = rememberBasicTooltipState(isPersistent = false)

Expand All @@ -48,10 +44,7 @@ internal fun AccessibleIconButton(
},
) {
IconButton(
onClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
onClick()
},
onClick = onClick,
modifier = modifier,
enabled = enabled,
colors = colors,
Expand Down

0 comments on commit 08dc884

Please sign in to comment.