mirror of
https://github.com/fankes/pagecurl-multiplatform.git
synced 2025-09-06 02:35:25 +08:00
Add observable progress
This commit is contained in:
@@ -6,6 +6,7 @@ import androidx.compose.animation.core.TwoWayConverter
|
||||
import androidx.compose.animation.core.VisibilityThreshold
|
||||
import androidx.compose.animation.core.keyframes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.Saver
|
||||
@@ -53,6 +54,8 @@ public class PageCurlState(
|
||||
public var current: Int by mutableStateOf(initialCurrent)
|
||||
internal set
|
||||
|
||||
public val progress: Float get() = internalState?.progress ?: 0f
|
||||
|
||||
internal var internalState: InternalState? by mutableStateOf(null)
|
||||
|
||||
internal fun setup(constraints: Constraints) {
|
||||
@@ -101,6 +104,16 @@ public class PageCurlState(
|
||||
|
||||
var animateJob: Job? = null
|
||||
|
||||
val progress: Float by derivedStateOf {
|
||||
if (forward.value != rightEdge) {
|
||||
1f - forward.value.centerX / constraints.maxWidth
|
||||
} else if (backward.value != leftEdge) {
|
||||
-backward.value.centerX / constraints.maxWidth
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun reset() {
|
||||
forward.snapTo(rightEdge)
|
||||
backward.snapTo(leftEdge)
|
||||
@@ -134,6 +147,9 @@ public class PageCurlState(
|
||||
}
|
||||
|
||||
public data class Edge(val top: Offset, val bottom: Offset) {
|
||||
|
||||
internal val centerX: Float = (top.x + bottom.x) * 0.5f
|
||||
|
||||
internal companion object {
|
||||
val VectorConverter: TwoWayConverter<Edge, AnimationVector4D> =
|
||||
TwoWayConverter(
|
||||
|
Reference in New Issue
Block a user