Skip to content

Commit 14ce5bd

Browse files
committed
library: Overscroll: Modify the default spring
1 parent 6b56ed5 commit 14ce5bd

File tree

1 file changed

+8
-10
lines changed
  • miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/utils

1 file changed

+8
-10
lines changed

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/utils/Overscroll.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import kotlinx.coroutines.launch
3131
import top.yukonga.miuix.kmp.basic.LocalPullToRefreshState
3232
import top.yukonga.miuix.kmp.basic.RefreshState
3333
import kotlin.math.abs
34-
import kotlin.math.exp
3534
import kotlin.math.sign
3635
import kotlin.math.sqrt
3736

@@ -52,11 +51,9 @@ import kotlin.math.sqrt
5251
@Stable
5352
fun parabolaScrollEasing(currentOffset: Float, newOffset: Float, p: Float = 50f, density: Float): Float {
5453
val realP = p * density
55-
val distance = abs(currentOffset + newOffset / 2)
56-
val ratio = (realP / (sqrt(realP * distance.coerceAtLeast(Float.MIN_VALUE)))).coerceIn(Float.MIN_VALUE, 1f)
57-
val nonLinearRatio = ratio * (1 - exp(-distance / realP))
54+
val ratio = (realP / (sqrt(realP * abs(currentOffset + newOffset / 2).coerceAtLeast(Float.MIN_VALUE)))).coerceIn(Float.MIN_VALUE, 1f)
5855
return if (sign(currentOffset) == sign(newOffset)) {
59-
currentOffset + newOffset * nonLinearRatio
56+
currentOffset + newOffset * ratio
6057
} else {
6158
currentOffset + newOffset
6259
}
@@ -67,12 +64,12 @@ internal val DefaultParabolaScrollEasing: (currentOffset: Float, newOffset: Floa
6764
get() {
6865
val density = LocalDensity.current.density
6966
return { currentOffset, newOffset ->
70-
parabolaScrollEasing(currentOffset, newOffset, density = density)
67+
parabolaScrollEasing(currentOffset, newOffset, 20f, density)
7168
}
7269
}
7370

74-
internal const val OutBoundSpringStiff = 150f
75-
internal const val OutBoundSpringDamp = 0.86f
71+
internal const val OutBoundSpringStiff = 180f
72+
internal const val OutBoundSpringDamp = 1f
7673

7774
/**
7875
* @see overScrollOutOfBound
@@ -267,7 +264,8 @@ fun Modifier.overScrollOutOfBound(
267264
}
268265
lastFlingAnimator = Animatable(offset)
269266
lastFlingAnimator.animateTo(
270-
0f, spring(currentSpringDamp, currentSpringStiff, visibilityThreshold),
267+
0f,
268+
spring(currentSpringDamp, currentSpringStiff, visibilityThreshold),
271269
if (currentIsVertical) realAvailable.y else realAvailable.x
272270
) {
273271
offset = currentScrollEasing(offset, value - offset)
@@ -305,5 +303,5 @@ class OverScrollState {
305303
*
306304
* @see OverScrollState
307305
*/
308-
val LocalOverScrollState = compositionLocalOf<OverScrollState> { OverScrollState() }
306+
val LocalOverScrollState = compositionLocalOf { OverScrollState() }
309307

0 commit comments

Comments
 (0)