Skip to content

Commit

Permalink
Play haptic feedback
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
saket committed Feb 3, 2024
1 parent 49b9422 commit 723200f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
Expand Down Expand Up @@ -72,6 +75,7 @@ fun SwipeableActionsBox(
}

val scope = rememberCoroutineScope()
val hapticFeedback = LocalHapticFeedback.current
Box(
modifier = Modifier
.onSizeChanged { state.layoutWidth = it.width }
Expand All @@ -81,6 +85,7 @@ fun SwipeableActionsBox(
enabled = !state.isResettingOnRelease,
onDragStopped = {
scope.launch {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
state.handleOnDragStopped()
}
},
Expand All @@ -98,6 +103,12 @@ fun SwipeableActionsBox(
content = { action.value.icon() }
)
}

if (state.hasCrossedSwipeThreshold()) {
LaunchedEffect(state.visibleAction) {
hapticFeedback.performHapticFeedback(HapticFeedbackType.TextHandleMove)
}
}
}

@Composable
Expand Down

0 comments on commit 723200f

Please sign in to comment.