Hi, I've been struggling for a few days now and I ...
# glance
m
Hi, I've been struggling for a few days now and I just can't get to make the simplest thing work. What am I doing wrong? I have a simple widget with
LazyColumn
but it seems like it composes ALL items in the list regardless if they are visible or not. Effectively behaving like
Column
with scroll
Copy code
class TestWidget : GlanceAppWidget() {
    override val sizeMode = SizeMode.Exact

    override suspend fun provideGlance(context: Context, id: GlanceId) {
        provideContent {
            LazyColumn(GlanceModifier.fillMaxSize().background(Color.Red).appWidgetBackground()) {
                items(100) {
                    Log.d("TestWidget", "Item: $it")
                    Text(
                        text = "$it",
                        modifier = GlanceModifier.padding(10.dp),
                    )
                }
            }
        }
    }
}
So as soon as I add this widget it get logs printed to all items
Normally I would not have noticed, but in my actual widget I have some bitmaps loaded in items and it immediately runs out of memory
From searching online it seems like Glance LazyColumn is not even mean to be lazy? Is this true? And if so then why is it called "Lazy"Column?
b
It was named that for parity with jetpack compose. Under the hood, it becomes a list, and it follows the platform's implementation of how that works. For older version of android, that meant an adapter that called back to the apps, but that behavior has changed more recently.
The other consideration is if the layout will be lazy on the appwidget's end, or the host's end. If the collection was truly lazy on the appwidget's process, then the launcher would need to wake it up more frequently when a user interacts with it, possibly affecting system performance. If the appwidget's process does a bunch of work up front and then sends a large number of remote views over, the host (launcher usually) won't have to make callbacks
If you're interested in specifically how glance handles lazy columns, this is the file that translates them to remote views https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:glance/g[…]ors/LazyListTranslator.kt?q=LazyListTranslator.kt&ss=androidx