Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuttering In LazyColumn #234

Open
9 tasks done
mandrachek opened this issue Nov 14, 2024 · 1 comment
Open
9 tasks done

Stuttering In LazyColumn #234

mandrachek opened this issue Nov 14, 2024 · 1 comment

Comments

@mandrachek
Copy link

mandrachek commented Nov 14, 2024

About this issue

  • Stuttering when scrolling in a LazyList
LazyColumn() {
        items(journals) { journal ->
            JournalRow(
                journal = journal,
                apiUrl = journalViewModel.apiUrl,
            )
        }
    }

And

@Composable
fun JournalRow(
    journal: JournalEntry,
    modifier: Modifier = Modifier,
    apiUrl: String? = null
) {
    Card(
        modifier = modifier
    ) {
        Column(modifier = Modifier.padding(16.dp)) {
            journal.comment?.let {
                Markdown(
                    content = it,
                    modifier = Modifier.fillMaxWidth(),
                    imageTransformer = Coil3ImageTransformerImpl,
                )
            }
        }
    }
}

In my Application, I call:

    private fun setupImageLoader() {
        SingletonImageLoader.setSafe {
            ImageLoader.Builder(this)
                .memoryCache {
                    MemoryCache.Builder()
                        .maxSizePercent(this, 0.25)
                        .build()
                }
                .diskCache {
                    DiskCache.Builder()
                        .directory(this.cacheDir.resolve("image_cache"))
                        .maxSizePercent(0.02)
                        .build()
                }
                .components {
                    add(KtorNetworkFetcherFactory(httpClient))
                    add(AnimatedImageDecoder.Factory())
                    add(VideoFrameDecoder.Factory())
                    add(SvgDecoder.Factory())
                }
                .build()
        }
    }
  • I have about 10 items in my list, and several of them have animated images, like

Image

A few of them have static images, like:
wilber

Scrolling down in the list is fine, but scrolling up, when I hit the bottom of an entry with an image, it "resists" scrolling up, bounces several times and I have to "push" through it for the scroll up gesture to work. This doesn't happen if I "fling" up, only when I scroll up slowly.

  • removing add(AnimatedImageDecoder.Factory()) and add(VideoFrameDecoder.Factory()) doesn't stop the gifs from animating or have any effect on the scrolling

  • removing the imageTransformer = Coil3ImageTransformerImpl, completely resolves the issue (but then I don't get images).

  • happens with both static and dyanmic images

I put in some logging, and whatever is going on is causing the LazyColumn to rapidly try and re-render those entires above the currently loaded one.

In them.

Details

  •  Used library version
    0.27.0
  •  Used platform
    Android
  • [-] Used support library version
  • [-] Used gradle build tools version
  •  Used tooling / Android Studio version
    Ladybug Patch 1
  •  Other used libraries, potential conflicting libraries
    compose-bom 2024.10.01
    androidx-compose-material3 1.3.1
    coil 3.0.2
    ktor 3.0.1

Checklist

@mandrachek mandrachek changed the title Stuttering In LazyList Stuttering In LazyColumn Nov 14, 2024
@mikepenz
Copy link
Owner

Thank you very much for the report @mandrachek

I suppose it's mostly a side-effect on the way how images are loaded in, and given they don't know their size beforehand, resulting in changing sizes in your area, which in a lazy list is problematic for scrolling.

It might be required to change the logic in that case to fix the image size being a placeholder and later on when being loaded:

https://github.com/mikepenz/multiplatform-markdown-renderer/blob/develop/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/model/ImageTransformer.kt#L27-L51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants