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+ }
0 commit comments