Skip to content

Commit ec21992

Browse files
committed
improve fast reply distance
1 parent 4fcf059 commit ec21992

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

  • presentation/src/main/java/org/monogram/presentation/features/chats/currentChat/components

presentation/src/main/java/org/monogram/presentation/features/chats/currentChat/components/FastReplyIndicator.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ import androidx.compose.ui.unit.Dp
3434
import androidx.compose.ui.unit.dp
3535
import kotlinx.coroutines.CoroutineScope
3636
import kotlinx.coroutines.launch
37+
import kotlin.math.pow
3738

38-
const val REPLY_TRIGGER_FRACTION = 0.35f
39-
const val MAX_SWIPE_FRACTION = 0.7f
39+
const val REPLY_TRIGGER_FRACTION = 0.4f
40+
const val MAX_SWIPE_FRACTION = 0.65f
4041
const val ICON_OFFSET_FRACTION = 0.1f
4142

4243
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@@ -51,7 +52,12 @@ fun FastReplyIndicator(
5152
val triggerDistance = maxWidth.value * REPLY_TRIGGER_FRACTION
5253
val dragged = (-dragOffsetX.value).coerceAtLeast(0f)
5354

54-
val progress = ((dragged - 48.dp.value) / (triggerDistance - 48.dp.value)).coerceIn(0f, 1f)
55+
val startOffset = 48.dp.value
56+
val effectiveDrag = (dragged - startOffset).coerceAtLeast(0f)
57+
val effectiveRange = (triggerDistance - startOffset).coerceAtLeast(1f)
58+
59+
val progress = (effectiveDrag / effectiveRange).coerceIn(0f, 1f).pow(1.3f)
60+
5561
val animatedProgress by
5662
animateFloatAsState(
5763
targetValue = progress,
@@ -60,7 +66,6 @@ fun FastReplyIndicator(
6066
stiffness = Spring.StiffnessLow
6167
)
6268
)
63-
println(progress)
6469

6570
val iconOffset = maxWidth * ICON_OFFSET_FRACTION
6671

@@ -78,7 +83,7 @@ fun FastReplyIndicator(
7883
contentAlignment = Alignment.Center
7984
) {
8085
AnimatedVisibility(
81-
visible = dragged > 48.dp.value,
86+
visible = dragged > startOffset,
8287
enter = fadeIn() + scaleIn(initialScale = 0.6f),
8388
exit = fadeOut() + scaleOut(targetScale = 0.6f)
8489
) {

0 commit comments

Comments
 (0)