File tree Expand file tree Collapse file tree
image/src/main/java/com/smarttoolfactory/image/zoom Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import androidx.compose.ui.Modifier
66import androidx.compose.ui.composed
77import androidx.compose.ui.draw.clipToBounds
88import androidx.compose.ui.geometry.Offset
9- import androidx.compose.ui.graphics.GraphicsLayerScope
109import androidx.compose.ui.graphics.graphicsLayer
1110import androidx.compose.ui.input.pointer.pointerInput
1211import 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-
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import androidx.compose.ui.unit.IntSize
1111import 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
Original file line number Diff line number Diff line change 11package 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+
You can’t perform that action at this time.
0 commit comments