androidandroid-studiokotlinandroid-jetpack-composeglance

Jetpack compose (Glance) widget doesn't recompose after bitmap image is loaded


I'm trying to create an Appwidget, using Glance Jetpack with .SVG image support.

I'm able to download the bitmap using

ImageRequest.Builder(this)
        .data(url)
        .decoderFactory(SvgDecoder.Factory())

...and as seen in the last line of logging, there's a non-null bitmap assigned to var coinImage.

The problem is, the widget doesn't seem to re-compose after the bitmap's value changes. I'm stuck seeing the circularProgressSpinner. widget screenshot What am I missing/doing wrong? Am I missing something foundational with the composition's state?

My code and logcat is at: https://gist.github.com/Alvtag/5bd46a2007e6c4f382d431e43aa96e80

Any help is appreciated!


Solution

  • Current Glance alpha05 does not support recomposition.

    Partial recomposition support will come in next version. You can use the Snapshot to access to it.

    Without recomposition you should follow this sample https://github.com/android/user-interface-samples/blob/main/AppWidget/app/src/main/java/com/example/android/appwidget/glance/image/ImageGlanceWidget.kt

    With recomposition support it will be simplified https://gist.github.com/marcelpinto/6df5e3e6ca42c6a0bf34b9f4b6eb1cff