-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImagesGridScreen.kt
47 lines (41 loc) · 1.42 KB
/
ImagesGridScreen.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package net.composegridperformance.feature.images
import androidx.activity.compose.ReportDrawnWhen
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
@Stable
data class ImageData(val ids: List<Int>)
@Composable
fun ImagesGridScreen(viewModel: ImagesGridViewModel = hiltViewModel()) {
val data by remember { mutableStateOf(viewModel.data) }
LazyVerticalGrid(
modifier = Modifier.testTag("items_grid"),
columns = GridCells.Fixed(3)
) {
items(
count = data.ids.size,
key = { index -> data.ids[index] },
) { index ->
ImageCard(data.ids[index])
}
}
ReportDrawnWhen { data.ids.isNotEmpty() }
}
@Composable
private fun ImageCard(id: Int) = AsyncImage(
modifier = Modifier
.testTag("grid_item")
.size(width = 200.dp, height = 300.dp),
model = "https://picsum.photos/id/$id/200/300",
contentDescription = null,
)