Skip to content

Commit 20d8586

Browse files
update ZoomableImageDemo and images
1 parent 2271b53 commit 20d8586

File tree

7 files changed

+298
-48
lines changed

7 files changed

+298
-48
lines changed

README.md

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
Collection of Images, Modifiers, utility functions for Jetpack Compose to expand
44
and enrich displaying, manipulating, scaling, resizing, zooming, and
5-
getting cropped `ImageBitmap` based on selection area
6-
7-
5+
getting cropped `ImageBitmap` based on selection area, before/after image to with handle to
6+
show partial of both images and more is cooking up
87

98
https://user-images.githubusercontent.com/35650605/177950258-b9c122a9-b6df-422f-b03b-dcfe9a294b18.mp4
109

11-
12-
1310
## ImageWithConstraints
11+
1412
A composable that lays out and draws a given `ImageBitmap`. This will attempt to
1513
size the composable according to the `ImageBitmap`'s given width and height.
1614

17-
`ImageScope` returns constraints, width and height of the drawing area based on `contentScale`
18-
* and rectangle of `imageBitmap` drawn. When a bitmap is displayed scaled to fit area of Composable
19-
* space used for drawing image is represented with `ImageScope.imageWidth` and
20-
* `ImageScope.imageHeight`.
21-
*
22-
* When we display a bitmap 1000x1000px with `ContentScale.Crop` if it's cropped to 500x500px
23-
* `ImageScope.rect` returns `IntRect(250,250,750,750)`.
15+
`ImageScope` returns constraints, width and height of the drawing area based on `contentScale`
16+
and rectangle of `imageBitmap` drawn. When a bitmap is displayed scaled to fit area of Composable
17+
space used for drawing image is represented with `ImageScope.imageWidth` and
18+
`ImageScope.imageHeight`. When we display a bitmap 1000x1000px with `ContentScale.Crop` if it's
19+
cropped to 500x500px `ImageScope.rect` returns `IntRect(250,250,750,750)`.
2420

2521
This composable enables building other `Image` based Composables that require you to know
26-
spaces around `ImageBitmap` with `ContentScale ` or which section of Bitmap is drawn to `Canvas`
22+
spaces around `ImageBitmap` based on `ContentScale ` or which section of Bitmap is drawn to `Canvas`
2723

2824
```kotlin
2925
@Composable
@@ -39,10 +35,12 @@ fun ImageWithConstraints(
3935
drawImage: Boolean = true,
4036
content: @Composable ImageScope.() -> Unit = {}
4137
) {
38+
imageScope: ImageScope->
4239

4340
}
4441
```
45-
returns `ImageScope` which is
42+
43+
returns `ImageScope` which is
4644

4745
```
4846
@Stable
@@ -102,13 +100,14 @@ interface ImageScope {
102100
```
103101

104102
* drawImage param is to set whether this Composable should draw on Canvas. `ImageWithConstraints`
105-
can be used not only for drawing but providing required info for its `content` or child
106-
Composables so child can draw `ImageBitmap` as required by developer.
103+
can be used not only for drawing but providing required info for its `content` or child
104+
Composables so child can draw `ImageBitmap` as required by developer.
107105

108106
## ImageWithThumbnail
107+
109108
`ImageWithThumbnail` displays thumbnail of bitmap it draws in corner specified
110-
by `ThumbnailState.position`. When touch position is close to thumbnail position
111-
if `ThumbnailState.dynamicPosition` is set to true moves thumbnail
109+
by `ThumbnailState.position`. When touch position is close to thumbnail position
110+
if `ThumbnailState.dynamicPosition` is set to true moves thumbnail
112111
to corner specified by `ThumbnailState.moveTo`
113112

114113
```kotlin
@@ -130,13 +129,14 @@ fun ImageWithThumbnail(
130129
onThumbnailCenterChange: ((Offset) -> Unit)? = null,
131130
content: @Composable ImageScope.() -> Unit = {}
132131
) {
133-
132+
134133
}
135134
```
136135

137136
## TransformLayout
138-
Composable that changes scale of its content from handles, translates its position
139-
when dragged inside bounds
137+
138+
Composable that changes scale of its content with handles, translates its position
139+
when dragged inside bounds.
140140

141141
```kotlin
142142
@Composable
@@ -150,16 +150,19 @@ fun TransformLayout(
150150
onUp: (Transform) -> Unit = {},
151151
content: @Composable () -> Unit
152152
) {
153-
153+
154154
}
155155
```
156156

157157
## MorphLayout
158-
Composable that changes dimensions of its content from handles, translates its position
159-
when dragged inside bounds. When using be mindful about the parent composable that contains this
160-
Composable since maximum width and height this Composable depends on how a Composable,
161-
Column for instance, lays out its children. It can be expanded upto remaining space if other
162-
sibling occupy rest of the parent's available space
158+
159+
Composable that changes dimensions of its content with handles, translates its position
160+
when dragged inside bounds.
161+
162+
⚠️ Be careful about maximum dimension can be assigned to this Composable with handles
163+
because maximum width and height depends on how a Composable,
164+
Column for instance, lays out its children. It can be expanded up to remaining space if other
165+
siblings occupy rest of the parent's available space set with parent `Layout`
163166

164167
```kotlin
165168
@Composable
@@ -179,9 +182,12 @@ fun MorphLayout(
179182
```
180183

181184
## ZoomableImage
182-
Zoomable image that zooms in and out in [ [minZoom], [maxZoom] ] interval and translates
183-
zoomed image based on pointer position.
185+
186+
Zoomable image that zooms in and out in [ [minZoom], [maxZoom] ] interval and translates
187+
zoomed image based on pointer position.
184188
Double tap gestures reset image translation and zoom to default values with animation.
189+
Callbacks notify user that gesture has started, going on finished with [ZoomData] that
190+
contains current transformation information
185191

186192
```kotlin
187193
@Composable
@@ -192,12 +198,41 @@ fun ZoomableImage(
192198
contentScale: ContentScale = ContentScale.Fit,
193199
contentDescription: String? = null,
194200
alpha: Float = DefaultAlpha,
201+
colorFilter: ColorFilter? = null,
202+
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
195203
initialZoom: Float = 1f,
196204
minZoom: Float = 1f,
197205
maxZoom: Float = 5f,
206+
limitPan: Boolean = true,
207+
zoomEnabled: Boolean = true,
208+
panEnabled: Boolean = true,
209+
rotationEnabled: Boolean = false,
198210
clipTransformToContentScale: Boolean = false,
199-
colorFilter: ColorFilter? = null,
200-
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
211+
consume: Boolean = true,
212+
onGestureStart: (ZoomData) -> Unit = {},
213+
onGesture: (ZoomData) -> Unit = {},
214+
onGestureEnd: (ZoomData) -> Unit = {}
201215
) {
202216
}
203217
```
218+
219+
## Modifier.zoom
220+
221+
Modifier that zooms, pans, and rotates any Composable it set to. when [clip] is true
222+
`Modifier.clipToBounds()` is used to limit content inside Composable bounds
223+
`consume` param is for `Modifier.pointerInput` to consume current events to prevent other
224+
gestures like scroll, drag or transform to initiate.
225+
Callbacks notify user that gesture has started, going on finished with [ZoomData] that
226+
contains current transformation information
227+
228+
```kotlin
229+
fun Modifier.zoom(
230+
key: Any?,
231+
consume: Boolean = true,
232+
clip: Boolean = true,
233+
zoomState: ZoomState,
234+
onGestureStart: (ZoomData) -> Unit = {},
235+
onGesture: (ZoomData) -> Unit = {},
236+
onGestureEnd: (ZoomData) -> Unit = {},
237+
)
238+
```

0 commit comments

Comments
 (0)