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