diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index e2cf8ff..4309c91 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -14,7 +14,6 @@
-
diff --git a/app/src/main/java/eu/wewox/pagecurl/page/CurlGesture.kt b/app/src/main/java/eu/wewox/pagecurl/page/CurlGesture.kt
index 11077f8..e51d447 100644
--- a/app/src/main/java/eu/wewox/pagecurl/page/CurlGesture.kt
+++ b/app/src/main/java/eu/wewox/pagecurl/page/CurlGesture.kt
@@ -1,13 +1,16 @@
package eu.wewox.pagecurl.page
+import androidx.compose.animation.core.VectorConverter
+import androidx.compose.animation.core.calculateTargetValue
+import androidx.compose.animation.splineBasedDecay
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.drag
import androidx.compose.foundation.gestures.forEachGesture
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.input.pointer.consumeAllChanges
import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.input.pointer.util.VelocityTracker
import androidx.compose.ui.unit.IntSize
import eu.wewox.pagecurl.config.CurlDirection
import eu.wewox.pagecurl.utils.rotate
@@ -25,6 +28,7 @@ fun Modifier.curlGesture(
return@pointerInput
}
+ val velocityTracker = VelocityTracker()
val startRect by lazy { direction.start.multiply(size) }
val endRect by lazy { direction.end.multiply(size) }
forEachGesture {
@@ -41,12 +45,26 @@ fun Modifier.curlGesture(
var dragCurrent = dragStart
drag(down.id) { change ->
dragCurrent = change.position
- change.consumeAllChanges()
+ velocityTracker.addPosition(System.currentTimeMillis(), dragCurrent)
+ change.consume()
val vector = (dragStart - dragCurrent).rotate(PI.toFloat() / 2)
onCurl(dragCurrent - vector, dragCurrent + vector)
}
- if (endRect.contains(dragCurrent)) {
+ val velocity = velocityTracker.calculateVelocity()
+ val decay = splineBasedDecay(this)
+ val target = decay.calculateTargetValue(
+ Offset.VectorConverter,
+ dragCurrent,
+ Offset(velocity.x, velocity.y)
+ ).let {
+ Offset(
+ it.x.coerceIn(0f, size.width.toFloat() - 1),
+ it.y.coerceIn(0f, size.height.toFloat() - 1)
+ )
+ }
+
+ if (endRect.contains(target)) {
onEnd()
} else {
onCancel()
diff --git a/build.gradle b/build.gradle
index 3ac42df..01af8cf 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,12 +1,12 @@
buildscript {
ext {
- compose_version = '1.2.0-alpha07'
+ compose_version = '1.2.0-beta01'
}
-}// Top-level build file where you can add configuration options common to all sub-projects/modules.
+}
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
- id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
+ id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {