AsyncImagePainter's placeholder/fallback/error is only updated when a state transition occurs
- Dominant language
- Kotlin
- Stars
- 11.9k
- Forks
- 788
- Avg merge
- 13h 39m
- Merged PRs (30d)
- 27
Description
**Describe the bug**
AsyncImagePainter's placeholder/fallback/error values are only updated when a state transition occurs. This is currently semi by design as those values are only used to overwrite the values provided by `ImageRequest`'s placeholder/fallback/error, however in practice this can be unexpected. To figure out:
- If we can update those values outside of state transitions caused by `ImageLoader` how does this affect `onState` and when it's called? Do we re-invoke the callback with `Loading` a second time if `placeholder` is updated?
**To Reproduce**
The following composable won't update to blue:
```kotlin
AsyncImage(
model = Unit, // Pass a value that errors immediately.
error = changingPainter(),
contentDescription = null,
)
@Composable
fun changingPainter(): Painter {
val painter by remember { mutableStateOf(ColorPainter(Color.Red)) }
LaunchedEffect(Unit) {
delay(1_000)
painter = ColorPainter(Color.Blue)
}
return painter
}
```
**Version**
Reproduced on `2.4.0`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the AsyncImage and AsyncImagePainter entry points described in the issue, then reproduce the changingPainter example with the reported version. Trace how placeholder, fallback, and error values are applied during ImageLoader state transitions, including when onState is called. Done means the intended update behavior is defined and the reproduction no longer remains red when the painter changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100