@@ -4,18 +4,27 @@ import androidx.compose.foundation.layout.Arrangement
4
4
import androidx.compose.foundation.layout.Column
5
5
import androidx.compose.foundation.layout.Row
6
6
import androidx.compose.foundation.layout.fillMaxWidth
7
+
8
+ import androidx.compose.foundation.layout.height
7
9
import androidx.compose.foundation.layout.padding
10
+ import androidx.compose.foundation.layout.width
8
11
import androidx.compose.foundation.lazy.LazyRow
9
12
import androidx.compose.foundation.lazy.items
13
+ import androidx.compose.foundation.rememberScrollState
14
+ import androidx.compose.foundation.verticalScroll
15
+ import androidx.compose.material.Card
16
+ import androidx.compose.material.Divider
10
17
import androidx.compose.material.Text
11
18
import androidx.compose.runtime.Composable
12
19
import androidx.compose.runtime.mutableStateListOf
13
20
import androidx.compose.runtime.mutableStateOf
14
21
import androidx.compose.runtime.remember
15
22
import androidx.compose.runtime.rememberCoroutineScope
23
+ import androidx.compose.ui.Alignment
16
24
import androidx.compose.ui.Modifier
17
25
import androidx.compose.ui.unit.dp
18
26
import com.trendyol.uicomponents.quantitypicker.QuantityIcons
27
+ import com.trendyol.uicomponents.quantitypicker.QuantityPicker
19
28
import com.trendyol.uicomponents.quantitypicker.QuantityPickerDefaults
20
29
import com.trendyol.uicomponents.quantitypicker.QuantityPickerDirection
21
30
import com.trendyol.uicomponents.quantitypicker.QuantityPickerViewData
@@ -29,9 +38,13 @@ import kotlinx.coroutines.launch
29
38
@Composable
30
39
fun QuantityPickerScreen () {
31
40
UIComponentsTheme {
32
- Column {
41
+ Column (
42
+ modifier = Modifier .verticalScroll(rememberScrollState())
43
+ ) {
33
44
ProductSliderSection ()
34
45
SingleProductSection ()
46
+ ProductWeightOptionsSection ()
47
+ ProductDetailSection ()
35
48
}
36
49
}
37
50
}
@@ -167,3 +180,82 @@ private fun ProductSliderSection() {
167
180
}
168
181
}
169
182
}
183
+
184
+ @Composable
185
+ private fun ProductDetailSection () {
186
+ Card (
187
+ modifier = Modifier .padding(16 .dp)
188
+ ) {
189
+ Column (
190
+ modifier = Modifier .padding(12 .dp),
191
+ verticalArrangement = Arrangement .spacedBy(8 .dp),
192
+ horizontalAlignment = Alignment .CenterHorizontally
193
+ ) {
194
+ Text (text = " Product Detail" )
195
+ Divider ()
196
+ QuantityPicker (
197
+ modifier = Modifier
198
+ .height(42 .dp)
199
+ .width(150 .dp),
200
+ quantityData = QuantityPickerViewData (currentQuantity = 2 ),
201
+ direction = QuantityPickerDirection .HORIZONTAL
202
+ )
203
+ }
204
+ }
205
+ }
206
+
207
+ @Composable
208
+ private fun ProductWeightOptionsSection () {
209
+ val coroutineScope = rememberCoroutineScope()
210
+ val products = remember {
211
+ mutableStateListOf(
212
+ ProductCardData (" 0" , " 500 gr" ),
213
+ ProductCardData (" 1" , " 1 kg" ),
214
+ ProductCardData (" 2" , " 2 kg" )
215
+ )
216
+ }
217
+
218
+ val onProductClick: (ProductCardData , Int ) -> Unit = remember(products) {
219
+ { product: ProductCardData , quantity: Int ->
220
+ val newQuantity = product.quantityData.currentQuantity + quantity
221
+ coroutineScope.launch {
222
+ val index = products.indexOf(product)
223
+ products[index] = product.copy(isLoading = true )
224
+ coroutineScope.launch {
225
+ delay(500 )
226
+ products[index] = product.copy(
227
+ isLoading = false ,
228
+ quantityData = product.quantityData.copy(
229
+ currentQuantity = newQuantity
230
+ )
231
+ )
232
+ }
233
+ }
234
+ }
235
+ }
236
+
237
+ Card (modifier = Modifier .padding(16 .dp)) {
238
+ Column (
239
+ verticalArrangement = Arrangement .spacedBy(12 .dp)
240
+ ) {
241
+ products.forEach { product ->
242
+ Row (
243
+ modifier = Modifier
244
+ .fillMaxWidth()
245
+ .padding(8 .dp),
246
+ horizontalArrangement = Arrangement .Absolute .SpaceBetween
247
+ ) {
248
+ Text (text = product.title)
249
+ QuantityPicker (
250
+ icons = QuantityIcons .default.copy(addIconBackgroundColor = QuantityPickerDefaults .defaultColor),
251
+ showLoading = product.isLoading,
252
+ quantityData = product.quantityData,
253
+ direction = QuantityPickerDirection .HORIZONTAL ,
254
+ onAddClick = { onProductClick(product, 1 ) },
255
+ onSubtractClick = { onProductClick(product, - 1 ) }
256
+ )
257
+ }
258
+ }
259
+ }
260
+ }
261
+ }
0 commit comments