Skip to content

Commit 93e8ee3

Browse files
update ZoomUtil, ZoomModifier and ZoomState
1 parent 5e070da commit 93e8ee3

3 files changed

Lines changed: 28 additions & 25 deletions

File tree

image/src/main/java/com/smarttoolfactory/image/zoom/ZoomModifier.kt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import androidx.compose.ui.Modifier
66
import androidx.compose.ui.composed
77
import androidx.compose.ui.draw.clipToBounds
88
import androidx.compose.ui.geometry.Offset
9-
import androidx.compose.ui.graphics.GraphicsLayerScope
109
import androidx.compose.ui.graphics.graphicsLayer
1110
import androidx.compose.ui.input.pointer.pointerInput
1211
import com.smarttoolfactory.gesture.detectTransformGestures
@@ -423,22 +422,3 @@ fun Modifier.zoom(
423422
onGestureEnd = {},
424423
onGesture = {}
425424
)
426-
427-
private fun GraphicsLayerScope.update(zoomState: ZoomState) {
428-
429-
// Set zoom
430-
val zoom = zoomState.zoom
431-
this.scaleX = zoom
432-
this.scaleY = zoom
433-
434-
// Set pan
435-
val pan = zoomState.pan
436-
val translationX = pan.x
437-
val translationY = pan.y
438-
this.translationX = translationX
439-
this.translationY = translationY
440-
441-
// Set rotation
442-
this.rotationZ = zoomState.rotation
443-
}
444-

image/src/main/java/com/smarttoolfactory/image/zoom/ZoomState.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.compose.ui.unit.IntSize
1111
import kotlinx.coroutines.coroutineScope
1212

1313

14-
1514
/**
1615
* * Create and [remember] the [ZoomState] based on the currently appropriate transform
1716
* configuration to allow changing pan, zoom, and rotation.
@@ -129,7 +128,7 @@ fun rememberZoomState(
129128
rotationEnabled: Boolean = false,
130129
limitPan: Boolean = false,
131130
vararg keys: Any?
132-
): ZoomState {
131+
): ZoomState {
133132
return remember(keys) {
134133
ZoomState(
135134
initialZoom = initialZoom,
@@ -197,15 +196,15 @@ open class ZoomState internal constructor(
197196
)
198197

199198

200-
open fun boundPan(lowerBound:Offset, upperBound:Offset) {
199+
open fun boundPan(lowerBound: Offset, upperBound: Offset) {
201200
animatablePan.updateBounds(lowerBound, upperBound)
202201
}
203202

204203
internal open suspend fun updateZoomState(
205204
size: IntSize,
206205
gesturePan: Offset,
207206
gestureZoom: Float,
208-
gestureRotate: Float,
207+
gestureRotate: Float = 1f,
209208
) {
210209
var zoom = zoom
211210

image/src/main/java/com/smarttoolfactory/image/zoom/ZoomUtil.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.smarttoolfactory.image.zoom
22

3+
import androidx.compose.ui.graphics.GraphicsLayerScope
4+
35
/**
46
* Calculate zoom level and zoom value when user double taps
57
*/
@@ -28,4 +30,26 @@ internal fun calculateZoom(
2830
}
2931
}
3032
return Pair(newZoomLevel, newZoom)
31-
}
33+
}
34+
35+
/**
36+
* Update graphic layer with [zoomState]
37+
*/
38+
internal fun GraphicsLayerScope.update(zoomState: ZoomState) {
39+
40+
// Set zoom
41+
val zoom = zoomState.zoom
42+
this.scaleX = zoom
43+
this.scaleY = zoom
44+
45+
// Set pan
46+
val pan = zoomState.pan
47+
val translationX = pan.x
48+
val translationY = pan.y
49+
this.translationX = translationX
50+
this.translationY = translationY
51+
52+
// Set rotation
53+
this.rotationZ = zoomState.rotation
54+
}
55+

0 commit comments

Comments
 (0)