@@ -3,22 +3,43 @@ package com.bumptech.glide.integration.compose
3
3
import android.content.Context
4
4
import androidx.compose.foundation.Image
5
5
import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.Spacer
7
+ import androidx.compose.foundation.layout.aspectRatio
8
+ import androidx.compose.foundation.layout.padding
6
9
import androidx.compose.foundation.layout.size
10
+ import androidx.compose.foundation.layout.width
11
+ import androidx.compose.material.icons.Icons
12
+ import androidx.compose.material.icons.filled.Email
13
+ import androidx.compose.runtime.mutableStateOf
14
+ import androidx.compose.runtime.remember
7
15
import androidx.compose.ui.Modifier
16
+ import androidx.compose.ui.draw.drawBehind
17
+ import androidx.compose.ui.geometry.Size
18
+ import androidx.compose.ui.geometry.isUnspecified
19
+ import androidx.compose.ui.graphics.Color
20
+ import androidx.compose.ui.semantics.contentDescription
21
+ import androidx.compose.ui.semantics.semantics
22
+ import androidx.compose.ui.test.captureToImage
23
+ import androidx.compose.ui.test.onNodeWithContentDescription
8
24
import androidx.compose.ui.unit.dp
9
25
import androidx.test.core.app.ApplicationProvider
10
26
import com.bumptech.glide.Glide
11
27
import com.bumptech.glide.integration.compose.test.GlideComposeRule
12
28
import com.bumptech.glide.load.DataSource
29
+ import com.bumptech.glide.test.compareToGolden
30
+ import com.bumptech.glide.test.pxToDp
13
31
import com.google.common.truth.Truth.assertThat
14
32
import org.junit.Rule
15
33
import org.junit.Test
34
+ import org.junit.rules.TestName
16
35
17
36
@OptIn(ExperimentalGlideComposeApi ::class )
18
37
class GlideSubcompositionTest {
19
- val context: Context = ApplicationProvider .getApplicationContext()
38
+ private val context: Context = ApplicationProvider .getApplicationContext()
20
39
21
- @get:Rule
40
+ @get:Rule(order = 1 )
41
+ val testName = TestName ()
42
+ @get:Rule(order = 2 )
22
43
val glideComposeRule = GlideComposeRule ()
23
44
24
45
@Test
@@ -162,5 +183,49 @@ class GlideSubcompositionTest {
162
183
glideComposeRule.waitForIdle()
163
184
assertThat(dataSource).isEqualTo(DataSource .MEMORY_CACHE )
164
185
}
186
+
187
+ // See #5272
188
+ @Test
189
+ fun glideSubcomposition_withPadding_appliesPaddingOnce () {
190
+ glideComposeRule.setContent {
191
+ val lastSize = remember { mutableStateOf(Size .Unspecified ) }
192
+
193
+ GlideSubcomposition (
194
+ model = null ,
195
+ modifier = Modifier
196
+ .semantics {
197
+ contentDescription = " test"
198
+ }
199
+ .width(400 .pxToDp())
200
+ .aspectRatio(1f )
201
+ .drawBehind {
202
+ if (lastSize.value.isUnspecified) {
203
+ lastSize.value = size
204
+ drawRect(Color .Blue )
205
+ } else if (lastSize.value != this .size) {
206
+ drawRect(Color .Red )
207
+ } else {
208
+ drawRect(Color .Blue )
209
+ }
210
+ }
211
+ .padding(80 .pxToDp()),
212
+ ) {
213
+ when (state) {
214
+ RequestState .Failure -> Image (
215
+ imageVector = Icons .Default .Email ,
216
+ contentDescription = " placeholder" ,
217
+ modifier = Modifier .width(400 .pxToDp())
218
+ )
219
+ RequestState .Loading -> Spacer (modifier = Modifier .size(100 .pxToDp()))
220
+ is RequestState .Success -> Image (painter = painter, contentDescription = null )
221
+ }
222
+ }
223
+ }
224
+ glideComposeRule.waitForIdle()
225
+ glideComposeRule.onNodeWithContentDescription(" test" )
226
+ .captureToImage()
227
+ .compareToGolden(testName.methodName)
228
+ }
165
229
}
166
230
231
+
0 commit comments