Skip to content

Commit 8247ac1

Browse files
rename pan, zoom, rotate, fling, moveToBounds params
1 parent 7a03fb4 commit 8247ac1

File tree

7 files changed

+138
-145
lines changed

7 files changed

+138
-145
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fun Modifier.enhancedZoom(
4646

4747
val coroutineScope = rememberCoroutineScope()
4848

49-
val boundPan = enhancedZoomState.limitPan && !enhancedZoomState.rotationEnabled
49+
val boundPan = enhancedZoomState.limitPan && !enhancedZoomState.rotatable
5050
val clipToBounds = (clip || boundPan)
5151

5252
val transformModifier = Modifier.pointerInput(key) {
@@ -158,7 +158,7 @@ fun Modifier.enhancedZoom(
158158

159159
val coroutineScope = rememberCoroutineScope()
160160

161-
val boundPan = enhancedZoomState.limitPan && !enhancedZoomState.rotationEnabled
161+
val boundPan = enhancedZoomState.limitPan && !enhancedZoomState.rotatable
162162
val clipToBounds = (clip || boundPan)
163163

164164
val transformModifier = Modifier.pointerInput(key1,key2) {
@@ -271,7 +271,7 @@ fun Modifier.enhancedZoom(
271271

272272
val coroutineScope = rememberCoroutineScope()
273273

274-
val boundPan = enhancedZoomState.limitPan && !enhancedZoomState.rotationEnabled
274+
val boundPan = enhancedZoomState.limitPan && !enhancedZoomState.rotatable
275275
val clipToBounds = (clip || boundPan)
276276

277277
val transformModifier = Modifier.pointerInput(keys) {

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

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ import androidx.compose.ui.unit.IntSize
2323
* @param initialZoom zoom set initially
2424
* @param minZoom minimum zoom value
2525
* @param maxZoom maximum zoom value
26-
* @param flingGestureEnabled when set to true dragging pointer builds up velocity. When last
27-
* pointer leaves Composable a movement invoked against friction till velocity drops down
26+
* @param fling when set to true dragging pointer builds up velocity. When last
27+
* pointer leaves Composable a movement invoked against friction till velocity drops below
2828
* to threshold
29-
* @param moveToBoundsEnabled when set to true if image zoom is lower than initial zoom or
29+
* @param moveToBounds when set to true if image zoom is lower than initial zoom or
3030
* panned out of image boundaries moves back to bounds with animation.
31-
* ##Note
32-
* Currently rotating back to borders is not available
33-
* @param zoomEnabled when set to true zoom is enabled
34-
* @param panEnabled when set to true pan is enabled
35-
* @param rotationEnabled when set to true rotation is enabled
31+
* @param zoomable when set to true zoom is enabled
32+
* @param pannable when set to true pan is enabled
33+
* @param rotatable when set to true rotation is enabled
3634
* @param limitPan limits pan to bounds of parent Composable. Using this flag prevents creating
3735
* empty space on sides or edges of parent
3836
*/
@@ -42,11 +40,11 @@ fun rememberEnhancedZoomState(
4240
initialZoom: Float = 1f,
4341
minZoom: Float = 1f,
4442
maxZoom: Float = 5f,
45-
flingGestureEnabled: Boolean = false,
46-
moveToBoundsEnabled: Boolean = true,
47-
zoomEnabled: Boolean = true,
48-
panEnabled: Boolean = true,
49-
rotationEnabled: Boolean = false,
43+
fling: Boolean = false,
44+
moveToBounds: Boolean = true,
45+
zoomable: Boolean = true,
46+
pannable: Boolean = true,
47+
rotatable: Boolean = false,
5048
limitPan: Boolean = false,
5149
key1: Any? = Unit
5250
): EnhancedZoomState {
@@ -56,11 +54,11 @@ fun rememberEnhancedZoomState(
5654
initialZoom = initialZoom,
5755
minZoom = minZoom,
5856
maxZoom = maxZoom,
59-
flingGestureEnabled = flingGestureEnabled,
60-
moveToBoundsEnabled = moveToBoundsEnabled,
61-
zoomEnabled = zoomEnabled,
62-
panEnabled = panEnabled,
63-
rotationEnabled = rotationEnabled,
57+
fling = fling,
58+
moveToBounds = moveToBounds,
59+
zoomable = zoomable,
60+
pannable = pannable,
61+
rotatable = rotatable,
6462
limitPan = limitPan
6563
)
6664
}
@@ -84,16 +82,14 @@ fun rememberEnhancedZoomState(
8482
* @param initialZoom zoom set initially
8583
* @param minZoom minimum zoom value
8684
* @param maxZoom maximum zoom value
87-
* @param flingGestureEnabled when set to true dragging pointer builds up velocity. When last
88-
* pointer leaves Composable a movement invoked against friction till velocity drops down
85+
* @param fling when set to true dragging pointer builds up velocity. When last
86+
* pointer leaves Composable a movement invoked against friction till velocity drops below
8987
* to threshold
90-
* @param moveToBoundsEnabled when set to true if image zoom is lower than initial zoom or
88+
* @param moveToBounds when set to true if image zoom is lower than initial zoom or
9189
* panned out of image boundaries moves back to bounds with animation.
92-
* ##Note
93-
* Currently rotating back to borders is not available
94-
* @param zoomEnabled when set to true zoom is enabled
95-
* @param panEnabled when set to true pan is enabled
96-
* @param rotationEnabled when set to true rotation is enabled
90+
* @param zoomable when set to true zoom is enabled
91+
* @param pannable when set to true pan is enabled
92+
* @param rotatable when set to true rotation is enabled
9793
* @param limitPan limits pan to bounds of parent Composable. Using this flag prevents creating
9894
* empty space on sides or edges of parent
9995
*/
@@ -103,11 +99,11 @@ fun rememberEnhancedZoomState(
10399
initialZoom: Float = 1f,
104100
minZoom: Float = 1f,
105101
maxZoom: Float = 5f,
106-
flingGestureEnabled: Boolean = false,
107-
moveToBoundsEnabled: Boolean = true,
108-
zoomEnabled: Boolean = true,
109-
panEnabled: Boolean = true,
110-
rotationEnabled: Boolean = false,
102+
fling: Boolean = false,
103+
moveToBounds: Boolean = true,
104+
zoomable: Boolean = true,
105+
pannable: Boolean = true,
106+
rotatable: Boolean = false,
111107
limitPan: Boolean = false,
112108
key1: Any?,
113109
key2: Any?,
@@ -118,11 +114,11 @@ fun rememberEnhancedZoomState(
118114
initialZoom = initialZoom,
119115
minZoom = minZoom,
120116
maxZoom = maxZoom,
121-
flingGestureEnabled = flingGestureEnabled,
122-
moveToBoundsEnabled = moveToBoundsEnabled,
123-
zoomEnabled = zoomEnabled,
124-
panEnabled = panEnabled,
125-
rotationEnabled = rotationEnabled,
117+
fling = fling,
118+
moveToBounds = moveToBounds,
119+
zoomable = zoomable,
120+
pannable = pannable,
121+
rotatable = rotatable,
126122
limitPan = limitPan
127123
)
128124
}
@@ -143,16 +139,14 @@ fun rememberEnhancedZoomState(
143139
* @param initialZoom zoom set initially
144140
* @param minZoom minimum zoom value
145141
* @param maxZoom maximum zoom value
146-
* @param flingGestureEnabled when set to true dragging pointer builds up velocity. When last
147-
* pointer leaves Composable a movement invoked against friction till velocity drops down
142+
* @param fling when set to true dragging pointer builds up velocity. When last
143+
* pointer leaves Composable a movement invoked against friction till velocity drops below
148144
* to threshold
149-
* @param moveToBoundsEnabled when set to true if image zoom is lower than initial zoom or
145+
* @param moveToBounds when set to true if image zoom is lower than initial zoom or
150146
* panned out of image boundaries moves back to bounds with animation.
151-
* ##Note
152-
* Currently rotating back to borders is not available
153-
* @param zoomEnabled when set to true zoom is enabled
154-
* @param panEnabled when set to true pan is enabled
155-
* @param rotationEnabled when set to true rotation is enabled
147+
* @param zoomable when set to true zoom is enabled
148+
* @param pannable when set to true pan is enabled
149+
* @param rotatable when set to true rotation is enabled
156150
* @param limitPan limits pan to bounds of parent Composable. Using this flag prevents creating
157151
* empty space on sides or edges of parent
158152
* @param keys are used to reset remember block to initial calculations. This can be used
@@ -165,11 +159,11 @@ fun rememberEnhancedZoomState(
165159
initialZoom: Float = 1f,
166160
minZoom: Float = 1f,
167161
maxZoom: Float = 5f,
168-
flingGestureEnabled: Boolean = false,
169-
moveToBoundsEnabled: Boolean = true,
170-
zoomEnabled: Boolean = true,
171-
panEnabled: Boolean = true,
172-
rotationEnabled: Boolean = false,
162+
fling: Boolean = false,
163+
moveToBounds: Boolean = true,
164+
zoomable: Boolean = true,
165+
pannable: Boolean = true,
166+
rotatable: Boolean = false,
173167
limitPan: Boolean = false,
174168
vararg keys: Any?
175169
): EnhancedZoomState {
@@ -179,11 +173,11 @@ fun rememberEnhancedZoomState(
179173
initialZoom = initialZoom,
180174
minZoom = minZoom,
181175
maxZoom = maxZoom,
182-
flingGestureEnabled = flingGestureEnabled,
183-
moveToBoundsEnabled = moveToBoundsEnabled,
184-
zoomEnabled = zoomEnabled,
185-
panEnabled = panEnabled,
186-
rotationEnabled = rotationEnabled,
176+
fling = fling,
177+
moveToBounds = moveToBounds,
178+
zoomable = zoomable,
179+
pannable = pannable,
180+
rotatable = rotatable,
187181
limitPan = limitPan
188182
)
189183
}

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ import kotlinx.coroutines.coroutineScope
2727
* @param initialZoom zoom set initially
2828
* @param minZoom minimum zoom value
2929
* @param maxZoom maximum zoom value
30-
* @param flingGestureEnabled when set to true dragging pointer builds up velocity. When last
30+
* @param fling when set to true dragging pointer builds up velocity. When last
3131
* pointer leaves Composable a movement invoked against friction till velocity drops down
3232
* to threshold
33-
* @param moveToBoundsEnabled when set to true if image zoom is lower than initial zoom or
33+
* @param moveToBounds when set to true if image zoom is lower than initial zoom or
3434
* panned out of image boundaries moves back to bounds with animation.
3535
* ##Note
3636
* Currently rotating back to borders is not available
37-
* @param zoomEnabled when set to true zoom is enabled
38-
* @param panEnabled when set to true pan is enabled
39-
* @param rotationEnabled when set to true rotation is enabled
37+
* @param zoomable when set to true zoom is enabled
38+
* @param pannable when set to true pan is enabled
39+
* @param rotatable when set to true rotation is enabled
4040
* @param limitPan limits pan to bounds of parent Composable. Using this flag prevents creating
4141
* empty space on sides or edges of parent
4242
*/
@@ -45,21 +45,21 @@ open class EnhancedZoomState constructor(
4545
initialZoom: Float = 1f,
4646
minZoom: Float = .5f,
4747
maxZoom: Float = 5f,
48-
flingGestureEnabled: Boolean = false,
49-
moveToBoundsEnabled: Boolean = true,
50-
zoomEnabled: Boolean = true,
51-
panEnabled: Boolean = true,
52-
rotationEnabled: Boolean = false,
48+
fling: Boolean = false,
49+
moveToBounds: Boolean = true,
50+
zoomable: Boolean = true,
51+
pannable: Boolean = true,
52+
rotatable: Boolean = false,
5353
limitPan: Boolean = false
5454
) : BaseEnhancedZoomState(
5555
initialZoom = initialZoom,
5656
minZoom = minZoom,
5757
maxZoom = maxZoom,
58-
flingGestureEnabled = flingGestureEnabled,
59-
moveToBoundsEnabled = moveToBoundsEnabled,
60-
zoomEnabled = zoomEnabled,
61-
panEnabled = panEnabled,
62-
rotationEnabled = rotationEnabled,
58+
fling = fling,
59+
moveToBounds = moveToBounds,
60+
zoomable = zoomable,
61+
pannable = pannable,
62+
rotatable = rotatable,
6363
limitPan = limitPan
6464
) {
6565

@@ -116,20 +116,20 @@ open class BaseEnhancedZoomState constructor(
116116
initialZoom: Float = 1f,
117117
minZoom: Float = .5f,
118118
maxZoom: Float = 5f,
119-
val flingGestureEnabled: Boolean = true,
120-
val moveToBoundsEnabled: Boolean = true,
121-
zoomEnabled: Boolean = true,
122-
panEnabled: Boolean = true,
123-
rotationEnabled: Boolean = false,
119+
val fling: Boolean = true,
120+
val moveToBounds: Boolean = true,
121+
zoomable: Boolean = true,
122+
pannable: Boolean = true,
123+
rotatable: Boolean = false,
124124
limitPan: Boolean = false
125125
) : ZoomState(
126126
initialZoom = initialZoom,
127127
initialRotation = 0f,
128128
minZoom = minZoom,
129129
maxZoom = maxZoom,
130-
zoomEnabled = zoomEnabled,
131-
panEnabled = panEnabled,
132-
rotationEnabled = rotationEnabled,
130+
zoomable = zoomable,
131+
pannable = pannable,
132+
rotatable = rotatable,
133133
limitPan = limitPan
134134
) {
135135
private val velocityTracker = VelocityTracker()
@@ -151,26 +151,26 @@ open class BaseEnhancedZoomState constructor(
151151
)
152152

153153
// Fling Gesture
154-
if (flingGestureEnabled) {
154+
if (fling) {
155155
if (changes.size == 1) {
156156
addPosition(mainPointer.uptimeMillis, mainPointer.position)
157157
}
158158
}
159159
}
160160

161161
suspend fun onGestureEnd(onFinish: () -> Unit) {
162-
if (flingGestureEnabled && zoom > 1) {
162+
if (fling && zoom > 1) {
163163
fling()
164164
}
165-
if (moveToBoundsEnabled) {
165+
if (moveToBounds) {
166166
resetToValidBounds()
167167
}
168168
onFinish()
169169
}
170170

171171
// Double Tap
172172
suspend fun onDoubleTap(onAnimationEnd: () -> Unit) {
173-
if (flingGestureEnabled) {
173+
if (fling) {
174174
resetTracking()
175175
}
176176
resetWithAnimation()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fun Modifier.zoom(
4242
factory = {
4343
val coroutineScope = rememberCoroutineScope()
4444

45-
val boundPan = zoomState.limitPan && !zoomState.rotationEnabled
45+
val boundPan = zoomState.limitPan && !zoomState.rotatable
4646
val clipToBounds = (clip || boundPan)
4747

4848
var zoomLevel by remember { mutableStateOf(ZoomLevel.Min) }
@@ -158,7 +158,7 @@ fun Modifier.zoom(
158158
factory = {
159159
val coroutineScope = rememberCoroutineScope()
160160

161-
val boundPan = zoomState.limitPan && !zoomState.rotationEnabled
161+
val boundPan = zoomState.limitPan && !zoomState.rotatable
162162
val clipToBounds = (clip || boundPan)
163163

164164
var zoomLevel by remember { mutableStateOf(ZoomLevel.Min) }
@@ -272,7 +272,7 @@ fun Modifier.zoom(
272272
factory = {
273273
val coroutineScope = rememberCoroutineScope()
274274

275-
val boundPan = zoomState.limitPan && !zoomState.rotationEnabled
275+
val boundPan = zoomState.limitPan && !zoomState.rotatable
276276
val clipToBounds = (clip || boundPan)
277277

278278
var zoomLevel by remember { mutableStateOf(ZoomLevel.Min) }

0 commit comments

Comments
 (0)