Skip to content

Commit 371d103

Browse files
donaldchaifalhassen
authored andcommitted
Fall back to "loading" placeholder when all else fails.
Fixes regression from #5306 Similar to how regular [Glide requests work](https://github.com/bumptech/glide/blob/c9cc739ce84b204defb1933e5f5f47d7c4a530b7/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java#L304-L305), the "loading" placeholder is expected to be used if there's a null model and null "error" placeholder. GlideImage.kt used to mention this: "The resource and `Drawable` variants will be displayed if the request fails and no other failure handling is specified". Presumably, this verbiage was removed because Composeable placeholders were being broken, and for no other reason.
1 parent c9cc739 commit 371d103

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

integration/compose/src/androidTest/java/com/bumptech/glide/integration/compose/GlideImageErrorTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ class GlideImageErrorTest {
5050
.assert(expectDisplayedDrawable(errorDrawable))
5151
}
5252

53+
@Test
54+
fun loadingParameter_withError_isUsedWhenAllElseFails() {
55+
val description = "test"
56+
val resourceId = android.R.drawable.star_big_off
57+
glideComposeRule.setContent {
58+
GlideImage(
59+
model = null,
60+
contentDescription = description,
61+
loading = placeholder(resourceId),
62+
)
63+
}
64+
65+
glideComposeRule
66+
.onNodeWithContentDescription(description)
67+
.assert(expectDisplayedPainter(context, resourceId))
68+
}
69+
5370
@Test
5471
fun failureParameter_withErrorResourceId_displaysError() {
5572
val description = "test"
@@ -58,6 +75,7 @@ class GlideImageErrorTest {
5875
GlideImage(
5976
model = null,
6077
contentDescription = description,
78+
loading = placeholder(android.R.drawable.star_on), // arbitary; shouldn't be displayed.
6179
failure = placeholder(failureResourceId),
6280
)
6381
}

integration/compose/src/main/java/com/bumptech/glide/integration/compose/GlideModifier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ internal class GlideNode : DrawModifierNode, LayoutModifierNode, SemanticsModifi
434434
// Prefer the override Painters if set.
435435
val painter = when (state) {
436436
is RequestState.Loading -> loadingPlaceholder
437-
is RequestState.Failure -> errorPlaceholder
437+
is RequestState.Failure -> errorPlaceholder ?: loadingPlaceholder
438438
is RequestState.Success -> throw IllegalStateException()
439439
}
440440
val primary = if (painter != null) {

0 commit comments

Comments
 (0)