glide icon indicating copy to clipboard operation
glide copied to clipboard

GlideImage no longer works with Modifier.weight()

Open ryandt opened this issue 1 year ago • 0 comments

Integration libraries: okhttp3-4.9.1

Device/Android version: Pixel 4, Android 13

Issue details / Repro steps / Use case background:

I recently upgraded the Glide dependencies of the app that I work–Glide 4.15.1 -> Glide 5.0.0-rc01 and Glide Compose 1.0.0-beta01 -> 1.0.0-alpha.3. Upon doing so, a few GlideImage usages throughout the app failed to load their image resources. They all happened to have weighted sizes. After the update, the size in onSizeChanged() returns 0x0 whereas previously the initial size would be 0x0 and the subsequent size change would be non-zero once the weights were applied.

val imageSize = remember { mutableStateOf(IntSize.Zero) }
val placeholder = ColorDrawable(LocalContext.current.colorFromAttr(R.attr.some_color))
GlideImage(
    modifier = Modifier
        .weight(1f, false)
        .then(
            if (imageSize.value.width == 0) {
                Modifier.onSizeChanged {
                    if (it.width != 0) imageSize.value = it
                }
            } else Modifier,
        ),
    model = getSizedImageUrl(topStart, imageSize.value),
    loading = placeholder(placeholder),
    failure = placeholder(placeholder),
    contentDescription = null,
)

I created a demo project to demonstrate the bug. The first commit is with Glide Compose 1.0.0-beta01 and weights working; the second commit is with Glide Compose 1.0.0-alpha.3 and weights not working.

Does anyone have any thoughts on what may have caused this change in behavior? Possibly related to this? cc: @sjudd

ryandt avatar Feb 08 '24 20:02 ryandt