Skip to content

Commit

Permalink
fix: swipe to reply not working on first try (#3061)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods authored Jun 4, 2024
1 parent 00f3521 commit 0cb4489
Showing 1 changed file with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,34 +301,8 @@ private fun SwipableToReplyBox(
var didVibrateOnCurrentDrag by remember { mutableStateOf(false) }

// Finish the animation in the first 25% of the drag
val progressUntilAnimationCompletion = 0.33f
val progressUntilAnimationCompletion = 0.25f
val dragWidth = screenWidth * progressUntilAnimationCompletion
val dragState = remember {
AnchoredDraggableState(
initialValue = SwipeAnchor.CENTERED,
positionalThreshold = { dragWidth },
velocityThreshold = { screenWidth },
snapAnimationSpec = tween(),
decayAnimationSpec = splineBasedDecay(density),
confirmValueChange = { changedValue ->
if (changedValue == SwipeAnchor.START_TO_END) {
// Attempt to finish dismiss, notify reply intention
onSwipedToReply()
}
if (changedValue == SwipeAnchor.CENTERED) {
// Reset the haptic feedback when drag is stopped
didVibrateOnCurrentDrag = false
}
// Reject state change, only allow returning back to rest position
changedValue == SwipeAnchor.CENTERED
},
anchors = DraggableAnchors {
SwipeAnchor.CENTERED at 0f
SwipeAnchor.START_TO_END at screenWidth
}
)
}
val primaryColor = colorsScheme().primary

val currentViewConfiguration = LocalViewConfiguration.current
val scopedViewConfiguration = object : ViewConfiguration by currentViewConfiguration {
Expand All @@ -337,6 +311,33 @@ private fun SwipableToReplyBox(
get() = currentViewConfiguration.touchSlop * 3f
}
CompositionLocalProvider(LocalViewConfiguration provides scopedViewConfiguration) {
val dragState = remember {
AnchoredDraggableState(
initialValue = SwipeAnchor.CENTERED,
positionalThreshold = { dragWidth },
velocityThreshold = { screenWidth },
snapAnimationSpec = tween(),
decayAnimationSpec = splineBasedDecay(density),
confirmValueChange = { changedValue ->
if (changedValue == SwipeAnchor.START_TO_END) {
// Attempt to finish dismiss, notify reply intention
onSwipedToReply()
}
if (changedValue == SwipeAnchor.CENTERED) {
// Reset the haptic feedback when drag is stopped
didVibrateOnCurrentDrag = false
}
// Reject state change, only allow returning back to rest position
changedValue == SwipeAnchor.CENTERED
},
anchors = DraggableAnchors {
SwipeAnchor.CENTERED at 0f
SwipeAnchor.START_TO_END at screenWidth
}
)
}
val primaryColor = colorsScheme().primary

Box(
modifier = modifier.fillMaxSize(),
) {
Expand Down

0 comments on commit 0cb4489

Please sign in to comment.