Skip to content

Commit fe41f65

Browse files
donaldchaifalhassen
authored andcommitted
Rollback integration/{compose,ktx}/{src,api}/ to 00251a5
The previous Compose integration was fairly buggy, so this rolls things back to a "known good" state (commit 00251a5). * rollback integration/{compose,ktx}/{src,api}/ to 00251a5, retaining some regression tests added since then (since we don't want the same bugs again). * rollback build.gradle and settings.gradle files as needed to restore dependencies. * remove nullability annotations from RequestListener.java to allow things to continue building.
1 parent 5cfcb31 commit fe41f65

30 files changed

+501
-1945
lines changed

integration/compose/api/compose.api

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
public final class com/bumptech/glide/integration/compose/CrossFade : com/bumptech/glide/integration/compose/Transition$Factory {
2-
public static final field $stable I
3-
public static final field Companion Lcom/bumptech/glide/integration/compose/CrossFade$Companion;
4-
public fun <init> (Landroidx/compose/animation/core/AnimationSpec;)V
5-
public fun build ()Lcom/bumptech/glide/integration/compose/Transition;
6-
public fun equals (Ljava/lang/Object;)Z
7-
public fun hashCode ()I
8-
}
9-
10-
public final class com/bumptech/glide/integration/compose/CrossFade$Companion : com/bumptech/glide/integration/compose/Transition$Factory {
11-
public fun build ()Lcom/bumptech/glide/integration/compose/Transition;
12-
}
13-
141
public abstract interface annotation class com/bumptech/glide/integration/compose/ExperimentalGlideComposeApi : java/lang/annotation/Annotation {
152
}
163

174
public final class com/bumptech/glide/integration/compose/GlideImageKt {
18-
public static final fun GlideImage (Ljava/lang/Object;Ljava/lang/String;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/bumptech/glide/integration/compose/Placeholder;Lcom/bumptech/glide/integration/compose/Placeholder;Lcom/bumptech/glide/integration/compose/Transition$Factory;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V
19-
public static final fun GlideSubcomposition (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V
5+
public static final fun GlideImage (Ljava/lang/Object;Ljava/lang/String;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/bumptech/glide/integration/compose/Placeholder;Lcom/bumptech/glide/integration/compose/Placeholder;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
206
public static final fun placeholder (I)Lcom/bumptech/glide/integration/compose/Placeholder;
217
public static final fun placeholder (Landroid/graphics/drawable/Drawable;)Lcom/bumptech/glide/integration/compose/Placeholder;
22-
public static final fun placeholder (Landroidx/compose/ui/graphics/painter/Painter;)Lcom/bumptech/glide/integration/compose/Placeholder;
238
public static final fun placeholder (Lkotlin/jvm/functions/Function2;)Lcom/bumptech/glide/integration/compose/Placeholder;
249
}
2510

@@ -28,11 +13,6 @@ public abstract interface class com/bumptech/glide/integration/compose/GlidePrel
2813
public abstract fun getSize ()I
2914
}
3015

31-
public abstract interface class com/bumptech/glide/integration/compose/GlideSubcompositionScope {
32-
public abstract fun getPainter ()Landroidx/compose/ui/graphics/painter/Painter;
33-
public abstract fun getState ()Lcom/bumptech/glide/integration/compose/RequestState;
34-
}
35-
3616
public abstract class com/bumptech/glide/integration/compose/Placeholder {
3717
public static final field $stable I
3818
}
@@ -42,40 +22,3 @@ public final class com/bumptech/glide/integration/compose/PreloadKt {
4222
public static final fun rememberGlidePreloadingData-u6VnWhU (ILkotlin/jvm/functions/Function1;JILjava/lang/Integer;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)Lcom/bumptech/glide/integration/compose/GlidePreloadingData;
4323
}
4424

45-
public abstract class com/bumptech/glide/integration/compose/RequestState {
46-
public static final field $stable I
47-
}
48-
49-
public final class com/bumptech/glide/integration/compose/RequestState$Failure : com/bumptech/glide/integration/compose/RequestState {
50-
public static final field $stable I
51-
public static final field INSTANCE Lcom/bumptech/glide/integration/compose/RequestState$Failure;
52-
}
53-
54-
public final class com/bumptech/glide/integration/compose/RequestState$Loading : com/bumptech/glide/integration/compose/RequestState {
55-
public static final field $stable I
56-
public static final field INSTANCE Lcom/bumptech/glide/integration/compose/RequestState$Loading;
57-
}
58-
59-
public final class com/bumptech/glide/integration/compose/RequestState$Success : com/bumptech/glide/integration/compose/RequestState {
60-
public static final field $stable I
61-
public fun <init> (Lcom/bumptech/glide/load/DataSource;)V
62-
public final fun component1 ()Lcom/bumptech/glide/load/DataSource;
63-
public final fun copy (Lcom/bumptech/glide/load/DataSource;)Lcom/bumptech/glide/integration/compose/RequestState$Success;
64-
public static synthetic fun copy$default (Lcom/bumptech/glide/integration/compose/RequestState$Success;Lcom/bumptech/glide/load/DataSource;ILjava/lang/Object;)Lcom/bumptech/glide/integration/compose/RequestState$Success;
65-
public fun equals (Ljava/lang/Object;)Z
66-
public final fun getDataSource ()Lcom/bumptech/glide/load/DataSource;
67-
public fun hashCode ()I
68-
public fun toString ()Ljava/lang/String;
69-
}
70-
71-
public abstract interface class com/bumptech/glide/integration/compose/Transition {
72-
public abstract fun getDrawCurrent ()Lkotlin/jvm/functions/Function5;
73-
public abstract fun getDrawPlaceholder ()Lkotlin/jvm/functions/Function5;
74-
public abstract fun stop (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
75-
public abstract fun transition (Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
76-
}
77-
78-
public abstract interface class com/bumptech/glide/integration/compose/Transition$Factory {
79-
public abstract fun build ()Lcom/bumptech/glide/integration/compose/Transition;
80-
}
81-

integration/compose/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ dependencies {
5959
}
6060
implementation libs.compose.foundation
6161
implementation libs.compose.ui
62+
implementation libs.drawablepainter
6263
implementation libs.androidx.core.ktx
6364
debugImplementation libs.compose.ui.testmanifest
6465
testImplementation libs.compose.ui.testmanifest
6566
testImplementation libs.compose.ui.testjunit4
6667
testImplementation libs.junit
6768
testImplementation libs.robolectric
69+
testImplementation libs.androidx.appcompat
6870
testImplementation libs.androidx.junit
6971
testImplementation libs.androidx.test.runner
7072
androidTestImplementation libs.junit

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:OptIn(ExperimentalGlideComposeApi::class, ExperimentalCoroutinesApi::class)
2+
13
package com.bumptech.glide.integration.compose
24

35
import android.graphics.Canvas
@@ -14,6 +16,7 @@ import com.bumptech.glide.integration.compose.test.Constants
1416
import com.bumptech.glide.integration.compose.test.GlideComposeRule
1517
import com.bumptech.glide.integration.compose.test.assertDisplaysInstance
1618
import com.bumptech.glide.integration.compose.test.onNodeWithDefaultContentDescription
19+
import kotlinx.coroutines.ExperimentalCoroutinesApi
1720
import kotlinx.coroutines.test.runTest
1821
import org.junit.Rule
1922
import org.junit.Test
@@ -25,7 +28,6 @@ import org.junit.runners.Parameterized
2528
*
2629
* Transformable types are tested in [GlideImageDefaultTransformationTest].
2730
*/
28-
@OptIn(ExperimentalGlideComposeApi::class)
2931
@RunWith(Parameterized::class)
3032
class GlideImageCustomDrawableTransformationTest(
3133
private val contentScale: ContentScale,
@@ -34,8 +36,7 @@ class GlideImageCustomDrawableTransformationTest(
3436
// though it's only used by Parameters to create the test name.
3537
@Suppress("unused") private val name: String,
3638
) {
37-
@get:Rule
38-
val glideComposeRule = GlideComposeRule()
39+
@get:Rule val glideComposeRule = GlideComposeRule()
3940

4041
@Test
4142
fun glideImage_nonBitmapDrawable_doesNotThrow() = runTest {
@@ -97,9 +98,8 @@ class GlideImageCustomDrawableTransformationTest(
9798
@Suppress("DeprecatedCallableAddReplaceWith")
9899
private open class FakeDrawable : Drawable() {
99100
override fun draw(p0: Canvas) {}
100-
override fun setAlpha(p0: Int) {}
101-
override fun setColorFilter(p0: ColorFilter?) {}
102-
101+
override fun setAlpha(p0: Int) = throw UnsupportedOperationException()
102+
override fun setColorFilter(p0: ColorFilter?) = throw UnsupportedOperationException()
103103
@Deprecated("Deprecated in Java")
104104
override fun getOpacity(): Int = throw UnsupportedOperationException()
105105
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package com.bumptech.glide.integration.compose
88

99
import android.content.Context
10+
import android.content.res.Resources
1011
import android.graphics.drawable.Drawable
12+
import android.util.TypedValue
1113
import androidx.annotation.DrawableRes
1214
import androidx.compose.foundation.layout.size
1315
import androidx.compose.runtime.Composable
@@ -26,6 +28,7 @@ import com.bumptech.glide.integration.ktx.ExperimentGlideFlows
2628
import com.bumptech.glide.integration.ktx.Resource
2729
import com.bumptech.glide.integration.ktx.Status
2830
import com.bumptech.glide.integration.ktx.flow
31+
import kotlin.math.roundToInt
2932
import kotlinx.coroutines.ExperimentalCoroutinesApi
3033
import kotlinx.coroutines.flow.first
3134
import kotlinx.coroutines.test.runTest

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

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:OptIn(ExperimentalGlideComposeApi::class)
2+
13
package com.bumptech.glide.integration.compose
24

35
import android.content.Context
@@ -7,7 +9,6 @@ import androidx.compose.ui.test.onNodeWithContentDescription
79
import androidx.test.core.app.ApplicationProvider
810
import com.bumptech.glide.integration.compose.test.GlideComposeRule
911
import com.bumptech.glide.integration.compose.test.expectDisplayedDrawable
10-
import com.bumptech.glide.integration.compose.test.expectDisplayedPainter
1112
import com.bumptech.glide.integration.compose.test.expectDisplayedResource
1213
import com.bumptech.glide.integration.compose.test.expectNoDrawable
1314
import org.junit.Rule
@@ -17,12 +18,9 @@ import org.junit.Test
1718
* Avoids [com.bumptech.glide.load.engine.executor.GlideIdlingResourceInit] because we want to make
1819
* assertions about loads that have not yet completed.
1920
*/
20-
@OptIn(ExperimentalGlideComposeApi::class)
2121
class GlideImageErrorTest {
2222
private val context: Context = ApplicationProvider.getApplicationContext()
23-
24-
@get:Rule
25-
val glideComposeRule = GlideComposeRule()
23+
@get:Rule val glideComposeRule = GlideComposeRule()
2624

2725
@Test
2826
fun requestBuilderTransform_withErrorResourceId_displaysError() {
@@ -50,23 +48,6 @@ class GlideImageErrorTest {
5048
.assert(expectDisplayedDrawable(errorDrawable))
5149
}
5250

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-
7051
@Test
7152
fun failureParameter_withErrorResourceId_displaysError() {
7253
val description = "test"
@@ -75,14 +56,13 @@ class GlideImageErrorTest {
7556
GlideImage(
7657
model = null,
7758
contentDescription = description,
78-
loading = placeholder(android.R.drawable.star_on), // arbitary; shouldn't be displayed.
7959
failure = placeholder(failureResourceId),
8060
)
8161
}
8262

8363
glideComposeRule
8464
.onNodeWithContentDescription(description)
85-
.assert(expectDisplayedPainter(context, failureResourceId))
65+
.assert(expectDisplayedResource(failureResourceId))
8666
}
8767

8868
@Test
@@ -99,7 +79,7 @@ class GlideImageErrorTest {
9979

10080
glideComposeRule
10181
.onNodeWithContentDescription(description)
102-
.assert(expectDisplayedPainter(failureDrawable))
82+
.assert(expectDisplayedDrawable(failureDrawable))
10383
}
10484

10585
@Test
@@ -117,41 +97,49 @@ class GlideImageErrorTest {
11797
}
11898

11999
@Test
120-
fun failure_setViaFailureParameterWithResourceId_andRequestBuilderTransform_prefersFailureParameter() {
121-
val description = "test"
100+
fun failureParameter_withComposable_displaysComposable() {
122101
val failureResourceId = android.R.drawable.star_big_off
102+
val description = "test"
123103
glideComposeRule.setContent {
124104
GlideImage(
125105
model = null,
126-
contentDescription = description,
127-
failure = placeholder(failureResourceId),
128-
) {
129-
it.error(android.R.drawable.btn_star)
130-
}
106+
contentDescription = "none",
107+
failure =
108+
placeholder {
109+
// Nesting GlideImage is not really a good idea, but it's convenient for this test
110+
// because
111+
// we can use our helpers to assert on its contents.
112+
GlideImage(
113+
model = null,
114+
contentDescription = description,
115+
failure = placeholder(failureResourceId),
116+
)
117+
}
118+
)
131119
}
132120

133121
glideComposeRule
134122
.onNodeWithContentDescription(description)
135-
.assert(expectDisplayedPainter(context, failureResourceId))
123+
.assert(expectDisplayedResource(failureResourceId))
136124
}
137125

138126
@Test
139-
fun failure_setViaFailureParameterWithPainter_andRequestBuilderTransform_prefersFailurePainter() {
127+
fun failure_setViaFailureParameterWithResourceId_andRequestBuilderTransform_prefersFailureParameter() {
140128
val description = "test"
141-
val failurePainter = context.getDrawable(android.R.drawable.star_big_off).toPainter()
129+
val failureResourceId = android.R.drawable.star_big_off
142130
glideComposeRule.setContent {
143131
GlideImage(
144132
model = null,
145133
contentDescription = description,
146-
failure = placeholder(failurePainter),
134+
failure = placeholder(failureResourceId),
147135
) {
148136
it.error(android.R.drawable.btn_star)
149137
}
150138
}
151139

152140
glideComposeRule
153141
.onNodeWithContentDescription(description)
154-
.assert(expectDisplayedPainter(failurePainter))
142+
.assert(expectDisplayedResource(failureResourceId))
155143
}
156144

157145
@Test
@@ -170,7 +158,7 @@ class GlideImageErrorTest {
170158

171159
glideComposeRule
172160
.onNodeWithContentDescription(description)
173-
.assert(expectDisplayedPainter(failureDrawable))
161+
.assert(expectDisplayedDrawable(failureDrawable))
174162
}
175163

176164
@Test
@@ -188,4 +176,30 @@ class GlideImageErrorTest {
188176

189177
glideComposeRule.onNodeWithContentDescription(description).assert(expectNoDrawable())
190178
}
179+
180+
@Test
181+
fun failure_setViaFailureParameterWithComposable_andRequestBuilderTransform_showsComposable() {
182+
val description = "test"
183+
val failureResourceId = android.R.drawable.star_big_off
184+
glideComposeRule.setContent {
185+
GlideImage(
186+
model = null,
187+
contentDescription = "other",
188+
failure =
189+
placeholder {
190+
GlideImage(
191+
model = null,
192+
contentDescription = description,
193+
failure = placeholder(failureResourceId),
194+
)
195+
},
196+
) {
197+
it.error(android.R.drawable.btn_star)
198+
}
199+
}
200+
201+
glideComposeRule
202+
.onNodeWithContentDescription(description)
203+
.assert(expectDisplayedResource(failureResourceId))
204+
}
191205
}

0 commit comments

Comments
 (0)