This commit is contained in:
vfsfitvnm
2022-07-24 16:18:39 +02:00
parent e912bfed1c
commit 306122e3f3

View File

@@ -76,6 +76,10 @@ fun BottomSheet(
velocityTracker.addPointerInputChange(change)
state.dispatchRawDelta(dragAmount)
},
onDragCancel = {
velocityTracker.resetTracking()
state.snapTo(initialValue)
},
onDragEnd = {
val velocity = velocityTracker.calculateVelocity().y.absoluteValue
velocityTracker.resetTracking()
@@ -149,7 +153,7 @@ class BottomSheetState(
1f - (animatable.upperBound!! - animatable.value) / (animatable.upperBound!! - animatable.lowerBound!!)
}
fun collapse(animationSpec: AnimationSpec<Dp>) {
private fun collapse(animationSpec: AnimationSpec<Dp>) {
onWasExpandedChanged(false)
coroutineScope.launch {
animatable.animateTo(animatable.lowerBound!!, animationSpec)
@@ -179,6 +183,12 @@ class BottomSheetState(
expand(tween(300))
}
fun snapTo(value: Dp) {
coroutineScope.launch {
animatable.snapTo(value)
}
}
fun nestedScrollConnection(initialIsTopReached: Boolean = true): NestedScrollConnection {
return object : NestedScrollConnection {
var isTopReached = initialIsTopReached