@@ -3,10 +3,17 @@ package com.smarttoolfactory.image.zoom
33import androidx.compose.animation.core.Animatable
44import androidx.compose.animation.core.VectorConverter
55import androidx.compose.runtime.Composable
6+ import androidx.compose.runtime.Immutable
67import androidx.compose.runtime.remember
8+ import androidx.compose.ui.Modifier
79import androidx.compose.ui.geometry.Offset
810import kotlinx.coroutines.coroutineScope
911
12+ /* *
13+ * * Create and [remember] the [ZoomState] based on the currently appropriate transform
14+ * configuration to allow changing pan, zoom, and rotation.
15+ *
16+ */
1017@Composable
1118fun rememberZoomState (
1219 initialZoom : Float = 1f,
@@ -24,13 +31,18 @@ fun rememberZoomState(
2431 }
2532}
2633
27- class ZoomState internal constructor(
34+ /* *
35+ * * State of the zoom. Allows the developer to change zoom, pan, translate,
36+ * or get current state by
37+ * calling methods on this object. To be hosted and passed to [Modifier.zoom]
38+ */
39+ @Immutable
40+ open class ZoomState internal constructor(
2841 initialZoom : Float = 1f ,
2942 initialRotation : Float = 0f ,
3043 minZoom : Float = 1f ,
3144 maxZoom : Float = 5f
3245) {
33- internal var zoomLevel = ZoomLevel .Min
3446
3547 internal val zoomMin = minZoom.coerceAtLeast(.5f )
3648 internal val zoomMax = maxZoom.coerceAtLeast(1f )
@@ -69,27 +81,27 @@ class ZoomState internal constructor(
6981 )
7082 }
7183
72- suspend fun animatePanTo (pan : Offset ) = coroutineScope {
84+ internal suspend fun animatePanTo (pan : Offset ) = coroutineScope {
7385 animatablePan.animateTo(pan)
7486 }
7587
76- suspend fun animateZoomTo (zoom : Float ) = coroutineScope {
88+ internal suspend fun animateZoomTo (zoom : Float ) = coroutineScope {
7789 animatableZoom.animateTo(zoom)
7890 }
7991
80- suspend fun animateRotationTo (rotation : Float ) = coroutineScope {
92+ internal suspend fun animateRotationTo (rotation : Float ) = coroutineScope {
8193 animatableRotation.animateTo(rotation)
8294 }
8395
84- suspend fun snapPanTo (offset : Offset ) = coroutineScope {
96+ internal suspend fun snapPanTo (offset : Offset ) = coroutineScope {
8597 animatablePan.snapTo(offset)
8698 }
8799
88- suspend fun snapZoomTo (zoom : Float ) = coroutineScope {
100+ internal suspend fun snapZoomTo (zoom : Float ) = coroutineScope {
89101 animatableZoom.snapTo(zoom)
90102 }
91103
92- suspend fun snapRotationTo (rotation : Float ) = coroutineScope {
104+ internal suspend fun snapRotationTo (rotation : Float ) = coroutineScope {
93105 animatableRotation.snapTo(rotation)
94106 }
95107}
0 commit comments