@@ -24,49 +24,49 @@ import androidx.compose.runtime.Stable
24
24
25
25
@Stable
26
26
class ZoomState (
27
- initialZoomLevel : Float ,
28
- val zoomRange : ClosedFloatingPointRange <Float >,
29
- val onChangeZoomLevel : (Float ) -> Unit ,
30
- ) {
31
- private var functionalZoom = initialZoomLevel
27
+ initialZoomLevel : Float ,
28
+ val zoomRange : ClosedFloatingPointRange <Float >,
29
+ val onChangeZoomLevel : (Float ) -> Unit ,
30
+ ) {
31
+ private var functionalZoom = initialZoomLevel
32
32
33
- private val mutatorMutex = MutatorMutex ()
33
+ private val mutatorMutex = MutatorMutex ()
34
34
35
- /* *
36
- * Immediately set the current zoom level to [targetZoomLevel].
37
- */
38
- suspend fun absoluteZoom (targetZoomLevel : Float ) {
39
- mutatorMutex.mutate {
40
- functionalZoom = targetZoomLevel.coerceIn(zoomRange)
41
- onChangeZoomLevel(functionalZoom)
35
+ /* *
36
+ * Immediately set the current zoom level to [targetZoomLevel].
37
+ */
38
+ suspend fun absoluteZoom (targetZoomLevel : Float ) {
39
+ mutatorMutex.mutate {
40
+ functionalZoom = targetZoomLevel.coerceIn(zoomRange)
41
+ onChangeZoomLevel(functionalZoom)
42
+ }
42
43
}
43
- }
44
44
45
- /* *
46
- * Scale the current zoom level.
47
- */
48
- suspend fun scaleZoom (scalingFactor : Float ) {
49
- absoluteZoom(scalingFactor * functionalZoom)
50
- }
45
+ /* *
46
+ * Scale the current zoom level.
47
+ */
48
+ suspend fun scaleZoom (scalingFactor : Float ) {
49
+ absoluteZoom(scalingFactor * functionalZoom)
50
+ }
51
51
52
- /* *
53
- * Ease towards a specific zoom level
54
- *
55
- * @param animationSpec [AnimationSpec] used for the animation, default to tween over 500ms
56
- */
57
- suspend fun animatedZoom (
58
- targetZoomLevel : Float ,
59
- animationSpec : AnimationSpec <Float > = tween(durationMillis = 500),
60
- ) {
61
- mutatorMutex.mutate {
62
- Animatable (initialValue = functionalZoom).animateTo(
63
- targetValue = targetZoomLevel,
64
- animationSpec = animationSpec,
65
- ) {
66
- // this is called every animation frame
67
- functionalZoom = value.coerceIn(zoomRange)
68
- onChangeZoomLevel(functionalZoom)
69
- }
52
+ /* *
53
+ * Ease towards a specific zoom level
54
+ *
55
+ * @param animationSpec [AnimationSpec] used for the animation, default to tween over 500ms
56
+ */
57
+ suspend fun animatedZoom (
58
+ targetZoomLevel : Float ,
59
+ animationSpec : AnimationSpec <Float > = tween(durationMillis = 500),
60
+ ) {
61
+ mutatorMutex.mutate {
62
+ Animatable (initialValue = functionalZoom).animateTo(
63
+ targetValue = targetZoomLevel,
64
+ animationSpec = animationSpec,
65
+ ) {
66
+ // this is called every animation frame
67
+ functionalZoom = value.coerceIn(zoomRange)
68
+ onChangeZoomLevel(functionalZoom)
69
+ }
70
+ }
70
71
}
71
- }
72
72
}
0 commit comments