Tolriq
10/25/2021, 6:46 PMAndrey Kulikov
10/25/2021, 7:13 PMTolriq
10/25/2021, 7:30 PMAndrey Kulikov
10/25/2021, 7:52 PMTolriq
10/25/2021, 7:58 PMval items = remember(lazyPagingItems.itemCount) {
derivedStateOf {
List(lazyPagingItems.itemCount) { it }.windowed(stepSize, stepSize, true)
}
}
LazyColumn(
state = lazyListState,
contentPadding = PaddingValues(vertical = 8.dp),
content = {
item {
Header(viewModel)
}
items(items.value) { items ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 4.dp)
) {
items.map { lazyPagingItems[it] }.forEach {
AlbumEntryGrid(it, viewModel.getThumbnailImagePath(it)) {
if (it != null) {
navigator.navigateTo(AlbumDetailsScreenDestination(it))
}
}
}
repeat(stepSize - items.size) {
Spacer(modifier = Modifier.weight(1f))
}
}
}
}
)
@Composable
fun RowScope.AlbumEntryGrid(mediaItem: MediaItem?, thumbnailImagePath: ImagePath, onRowClick: () -> Unit) {
val finalMediaItem = mediaItem ?: MediaItem(title = "Placeholder")
Box(
Modifier
.clickable { onRowClick() }
.aspectRatio(1f)
.weight(1f)
.padding(4.dp)
.clip(RoundedCornerShape(8.dp)),
) {
val imageRequest = ImageRequest(
thumbnailImagePath,
exactSize = false,
debugTag = "AlbumEntryGrid"
)
Image(
imageRequestPainter = rememberImageRequestPainter(imageRequest = imageRequest),
contentDescription = null,
error = @Composable { Error(finalMediaItem) },
placeHolder = @Composable { SurfacePlaceHolder() },
contentScale = ContentScale.FillBounds,
modifier = Modifier
.aspectRatio(1f)
)
}
}
Tolriq
10/25/2021, 8:14 PMremember(lazyPagingItems.itemCount) {
derivedStateOf {
List(lazyPagingItems.itemCount) { it }.windowed(stepSize, stepSize, true)
}
}
Is triggering a recalculation of the derived state and so the tree when compose paging load a new page. (But the perf issue is also ocutring when all pages are loaded so it's not the root cause).
Is there something wrong with that approach to have a stable state that contains a list of number that must only be recreated when the actual itemcount change ?Andrey Kulikov
10/25/2021, 8:18 PMTolriq
10/25/2021, 8:23 PMval lazyListState = rememberLazyListState()
It's just defined earlier as I use the same when switching from list to gridTolriq
10/25/2021, 8:24 PM@Composable
inline fun LogCompositions(tag: String) {
if (ENABLE_DEBUG_COMPOSITION_LOGS && BuildConfig.DEBUG) {
val ref = remember { Ref(0) }
SideEffect {
ref.value++
Logger.logger.logError(tag, "Compositions: ${ref.value}", null, true)
}
}
}
Tolriq
10/25/2021, 8:24 PMTolriq
10/25/2021, 8:26 PMTolriq
10/28/2021, 3:23 PMval items = List(14000) { listOf(it, it, it) }
LazyColumn(
state = rememberLazyListState(),
content = {
items(items) { items ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp)
.background(Color.Red)
) {
items.forEach {
Surface(
color = Color.DarkGray,
modifier = Modifier
.clickable { /*onRowClick()*/ }
.weight(1f)
.aspectRatio(5f)
.padding(4.dp)) {}
}
}
}
}
)
Tolriq
10/28/2021, 3:24 PMTolriq
10/28/2021, 3:25 PM