mirror of
https://github.com/fankes/pagecurl-multiplatform.git
synced 2025-09-05 18:25:20 +08:00
Compose beta and velocity tracker
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -14,7 +14,6 @@
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
@@ -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<Offset>(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()
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user