This is a bit odd, in moving from 1.4 beta01 to be...
# compose
a
This is a bit odd, in moving from 1.4 beta01 to beta02 seeing an issue where we replace a BitmapPainter thats stored in state, doesn't work anymore. I can use a ColorPainter and it works fine.. more in reply
This is a sample showing similar code to what we have for real (some bridge code where we load a bitmap via Picasso and create a BitmapPainter once the load has finished).... We are migrating to Coil but thats been delayed... anyway this simple sample code hits the problem:
Copy code
internal object EmptyPainter : Painter() {
    override val intrinsicSize: Size get() = Size.Unspecified
    override fun DrawScope.onDraw() {}
}

@Composable
fun rememberMyPainter(): Painter? {
    val context = LocalContext.current
    val painter = remember { mutableStateOf<Painter?>(null) }

    if (painter.value == null) {
        DisposableEffect(Unit) {
            val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.num1)
            painter.value = BitmapPainter(image = bitmap.asImageBitmap())
            onDispose {}
        }
    }
    return painter.value
}

@Composable
fun TestDelayedPainter() {
    val painter = rememberMyPainter()
    Image(
        painter = painter ?: EmptyPainter,
        contentDescription = null,
    )
}
In the real code inside that DisposableEffect its actually calling something that will run later once a download completes, so we're in a coroutine scope / runnable when the write to state happens, but in creating a test app I found it didn't need to even go that far it just had to do the write from a side effect.