Skip to content

Commit 9f035d1

Browse files
add ZoomableListDemo
1 parent 5175b9c commit 9f035d1

File tree

9 files changed

+628
-39
lines changed

9 files changed

+628
-39
lines changed

README.md

Lines changed: 320 additions & 24 deletions
Large diffs are not rendered by default.

app/src/main/java/com/smarttoolfactory/composeimage/demo/zoom/AnimatedZoomDemo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fun AnimatedZoomDemo() {
2121
AnimatedZoomLayout(
2222
modifier = Modifier.fillMaxSize(),
2323
enabled = { zoom, pan, rotation ->
24-
(zoom > 1.2f)
24+
(zoom > 1f)
2525
}
2626
) {
2727
Text(

app/src/main/java/com/smarttoolfactory/composeimage/demo/zoom/EnhancedZoomDemo.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private fun EnhancedZoomableImageSample(imageBitmap: ImageBitmap, contentScale:
7676
moveToBounds = true,
7777
clipTransformToContentScale = true,
7878
enabled = { zoom, pan, rotation ->
79-
(zoom > 1.2f)
79+
(zoom > 1f)
8080
}
8181
)
8282

@@ -99,7 +99,7 @@ private fun EnhancedZoomableImageSample(imageBitmap: ImageBitmap, contentScale:
9999
moveToBounds = true,
100100
fling = true,
101101
enabled = { zoom, pan, rotation ->
102-
(zoom > 1.2f)
102+
(zoom > 1f)
103103
}
104104
)
105105

@@ -124,7 +124,7 @@ private fun EnhancedZoomableImageSample(imageBitmap: ImageBitmap, contentScale:
124124
moveToBounds = false,
125125
fling = true,
126126
enabled = { zoom, pan, rotation ->
127-
(zoom > 1.2f)
127+
(zoom > 1f)
128128
}
129129
)
130130

@@ -176,7 +176,7 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
176176
}
177177
},
178178
enabled = { zoom, pan, rotation ->
179-
zoom > 1.2f
179+
zoom > 1f
180180
}
181181
),
182182
bitmap = imageBitmap,
@@ -205,7 +205,7 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
205205
moveToBounds = true
206206
),
207207
enabled = { zoom, pan, rotation ->
208-
(zoom > 1.2f)
208+
(zoom > 1f)
209209
}
210210
),
211211
bitmap = imageBitmap,
@@ -235,7 +235,7 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
235235
fling = true
236236
),
237237
enabled = { zoom, pan, rotation ->
238-
(zoom > 1.2f)
238+
(zoom > 1f)
239239
}
240240
),
241241
bitmap = imageBitmap,
@@ -266,7 +266,7 @@ private fun EnhancedZoomModifierSample(imageBitmap: ImageBitmap) {
266266
fling = true
267267
),
268268
enabled = { zoom, pan, rotation ->
269-
(zoom > 1.2f)
269+
(zoom > 1f)
270270
}
271271
),
272272
bitmap = imageBitmap,
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
package com.smarttoolfactory.composeimage.demo.zoom
2+
3+
import android.annotation.SuppressLint
4+
import androidx.compose.foundation.Image
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.height
7+
import androidx.compose.foundation.shape.RoundedCornerShape
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.Immutable
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.draw.clip
12+
import androidx.compose.ui.layout.ContentScale
13+
import androidx.compose.ui.platform.LocalContext
14+
import androidx.compose.ui.unit.IntSize
15+
import androidx.compose.ui.unit.dp
16+
import coil.compose.rememberAsyncImagePainter
17+
import coil.request.ImageRequest
18+
import coil.size.Size
19+
import com.smarttoolfactory.composeimage.R
20+
import com.smarttoolfactory.image.zoom.enhancedZoom
21+
import com.smarttoolfactory.image.zoom.rememberEnhancedZoomState
22+
23+
@Immutable
24+
data class Snack(
25+
val id: Long,
26+
val name: String,
27+
val imageUrl: String,
28+
val price: Long,
29+
val tagline: String = "",
30+
val tags: Set<String> = emptySet()
31+
)
32+
33+
@SuppressLint("ModifierParameter")
34+
@Composable
35+
fun SnackCard(snack: Snack) {
36+
37+
38+
val painter = rememberAsyncImagePainter(
39+
model = ImageRequest.Builder(LocalContext.current)
40+
.data(snack.imageUrl)
41+
.placeholder(R.drawable.placeholder)
42+
.size(Size.ORIGINAL) // Set the target size to load the image at.
43+
.build()
44+
)
45+
46+
47+
Image(
48+
contentScale = ContentScale.FillBounds,
49+
modifier = Modifier
50+
.clip(RoundedCornerShape(20.dp))
51+
.enhancedZoom(
52+
clip = false,
53+
enhancedZoomState = rememberEnhancedZoomState(
54+
imageSize = IntSize(
55+
painter.intrinsicSize.width.toInt(),
56+
painter.intrinsicSize.height.toInt()
57+
),
58+
rotatable = false,
59+
limitPan = true
60+
),
61+
enabled = { zoom, pan, rotataion ->
62+
zoom > 1f
63+
}
64+
)
65+
.clip(RoundedCornerShape(20.dp))
66+
.fillMaxWidth()
67+
.height(300.dp),
68+
painter = painter,
69+
contentDescription = null
70+
)
71+
72+
}
73+
74+
val snacks = listOf(
75+
Snack(
76+
id = 1L,
77+
name = "Cupcake",
78+
tagline = "A tag line",
79+
imageUrl = "https://source.unsplash.com/pGM4sjt_BdQ",
80+
price = 299
81+
),
82+
Snack(
83+
id = 2L,
84+
name = "Donut",
85+
tagline = "A tag line",
86+
imageUrl = "https://source.unsplash.com/Yc5sL-ejk6U",
87+
price = 299
88+
),
89+
Snack(
90+
id = 3L,
91+
name = "Eclair",
92+
tagline = "A tag line",
93+
imageUrl = "https://source.unsplash.com/-LojFX9NfPY",
94+
price = 299
95+
),
96+
Snack(
97+
id = 4L,
98+
name = "Froyo",
99+
tagline = "A tag line",
100+
imageUrl = "https://source.unsplash.com/3U2V5WqK1PQ",
101+
price = 299
102+
),
103+
Snack(
104+
id = 5L,
105+
name = "Gingerbread",
106+
tagline = "A tag line",
107+
imageUrl = "https://source.unsplash.com/Y4YR9OjdIMk",
108+
price = 499
109+
),
110+
Snack(
111+
id = 6L,
112+
name = "Honeycomb",
113+
tagline = "A tag line",
114+
imageUrl = "https://source.unsplash.com/bELvIg_KZGU",
115+
price = 299
116+
),
117+
Snack(
118+
id = 7L,
119+
name = "Ice Cream Sandwich",
120+
tagline = "A tag line",
121+
imageUrl = "https://source.unsplash.com/YgYJsFDd4AU",
122+
price = 1299
123+
),
124+
Snack(
125+
id = 8L,
126+
name = "Jellybean",
127+
tagline = "A tag line",
128+
imageUrl = "https://source.unsplash.com/0u_vbeOkMpk",
129+
price = 299
130+
),
131+
Snack(
132+
id = 9L,
133+
name = "KitKat",
134+
tagline = "A tag line",
135+
imageUrl = "https://source.unsplash.com/yb16pT5F_jE",
136+
price = 549
137+
),
138+
Snack(
139+
id = 10L,
140+
name = "Lollipop",
141+
tagline = "A tag line",
142+
imageUrl = "https://source.unsplash.com/AHF_ZktTL6Q",
143+
price = 299
144+
),
145+
Snack(
146+
id = 11L,
147+
name = "Marshmallow",
148+
tagline = "A tag line",
149+
imageUrl = "https://source.unsplash.com/rqFm0IgMVYY",
150+
price = 299
151+
),
152+
Snack(
153+
id = 12L,
154+
name = "Nougat",
155+
tagline = "A tag line",
156+
imageUrl = "https://source.unsplash.com/qRE_OpbVPR8",
157+
price = 299
158+
),
159+
Snack(
160+
id = 13L,
161+
name = "Oreo",
162+
tagline = "A tag line",
163+
imageUrl = "https://source.unsplash.com/33fWPnyN6tU",
164+
price = 299
165+
),
166+
Snack(
167+
id = 14L,
168+
name = "Pie",
169+
tagline = "A tag line",
170+
imageUrl = "https://source.unsplash.com/aX_ljOOyWJY",
171+
price = 299
172+
),
173+
Snack(
174+
id = 15L,
175+
name = "Chips",
176+
imageUrl = "https://source.unsplash.com/UsSdMZ78Q3E",
177+
price = 299
178+
),
179+
Snack(
180+
id = 16L,
181+
name = "Pretzels",
182+
imageUrl = "https://source.unsplash.com/7meCnGCJ5Ms",
183+
price = 299
184+
),
185+
Snack(
186+
id = 17L,
187+
name = "Smoothies",
188+
imageUrl = "https://source.unsplash.com/m741tj4Cz7M",
189+
price = 299
190+
),
191+
Snack(
192+
id = 18L,
193+
name = "Popcorn",
194+
imageUrl = "https://source.unsplash.com/iuwMdNq0-s4",
195+
price = 299
196+
),
197+
Snack(
198+
id = 19L,
199+
name = "Almonds",
200+
imageUrl = "https://source.unsplash.com/qgWWQU1SzqM",
201+
price = 299
202+
),
203+
Snack(
204+
id = 20L,
205+
name = "Cheese",
206+
imageUrl = "https://source.unsplash.com/9MzCd76xLGk",
207+
price = 299
208+
),
209+
Snack(
210+
id = 21L,
211+
name = "Apples",
212+
tagline = "A tag line",
213+
imageUrl = "https://source.unsplash.com/1d9xXWMtQzQ",
214+
price = 299
215+
),
216+
Snack(
217+
id = 22L,
218+
name = "Apple sauce",
219+
tagline = "A tag line",
220+
imageUrl = "https://source.unsplash.com/wZxpOw84QTU",
221+
price = 299
222+
),
223+
Snack(
224+
id = 23L,
225+
name = "Apple chips",
226+
tagline = "A tag line",
227+
imageUrl = "https://source.unsplash.com/okzeRxm_GPo",
228+
price = 299
229+
),
230+
Snack(
231+
id = 24L,
232+
name = "Apple juice",
233+
tagline = "A tag line",
234+
imageUrl = "https://source.unsplash.com/l7imGdupuhU",
235+
price = 299
236+
),
237+
Snack(
238+
id = 25L,
239+
name = "Apple pie",
240+
tagline = "A tag line",
241+
imageUrl = "https://source.unsplash.com/bkXzABDt08Q",
242+
price = 299
243+
),
244+
Snack(
245+
id = 26L,
246+
name = "Grapes",
247+
tagline = "A tag line",
248+
imageUrl = "https://source.unsplash.com/y2MeW00BdBo",
249+
price = 299
250+
),
251+
Snack(
252+
id = 27L,
253+
name = "Kiwi",
254+
tagline = "A tag line",
255+
imageUrl = "https://source.unsplash.com/1oMGgHn-M8k",
256+
price = 299
257+
),
258+
Snack(
259+
id = 28L,
260+
name = "Mango",
261+
tagline = "A tag line",
262+
imageUrl = "https://source.unsplash.com/TIGDsyy0TK4",
263+
price = 299
264+
)
265+
)
266+
267+
val snacksOrdered = snacks.sortedBy {
268+
it.name.first()
269+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.smarttoolfactory.composeimage.demo.zoom
2+
3+
import androidx.compose.foundation.layout.Arrangement
4+
import androidx.compose.foundation.layout.PaddingValues
5+
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.foundation.lazy.LazyColumn
7+
import androidx.compose.foundation.lazy.items
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.unit.dp
11+
12+
@Composable
13+
fun ZoomableListDemo() {
14+
LazyColumn(
15+
modifier = Modifier.fillMaxSize(),
16+
contentPadding = PaddingValues(10.dp),
17+
verticalArrangement = Arrangement.spacedBy(10.dp)
18+
) {
19+
items(snacks) {
20+
SnackCard(snack = it)
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)