Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compose] Modifier is applied twice #5307

Closed
ln-12 opened this issue Oct 4, 2023 · 1 comment
Closed

[Compose] Modifier is applied twice #5307

ln-12 opened this issue Oct 4, 2023 · 1 comment

Comments

@ln-12
Copy link

ln-12 commented Oct 4, 2023

Glide Version: 4.16.0 / 1.0.0-alpha.5

Device/Android Version: compose preview, Pixel 7, Emulator (both API 33)

Issue details / Repro steps / Use case background:

I noticed that modifiers which are applied to a GlideImage, are applied twice. In the example shown below, you can see that the padding as well as the background modifier are applied two times. The expected behavior is that each modifier is only applied once so that the padding is actually only 10.dp and that the background is only visible once too.

image

My code example looks like this:

Column(
        modifier = Modifier.background(Color.Red)
) {
    GlideImage(
            model = R.drawable.lb_background,
            contentDescription = null,
            modifier = Modifier
                .padding(10.dp)
                .background(Color.Green)
                .height(150.dp)
                .fillMaxWidth()
                .clip(RoundedCornerShape(10.dp))
                .background(Color.Yellow),
            contentScale = ContentScale.Crop,
    )
}

As far as I can tell, the issue is related to this code block:

GlideSubcomposition(model, modifier, { requestBuilder }) {
if (state == RequestState.Loading && loadingComposable != null) {
loadingComposable()
} else if (state == RequestState.Failure && failureComposable != null) {
failureComposable()
} else {
Image(
painter,
contentDescription,
modifier,
alignment,
contentScale,
alpha,
colorFilter,
)
}
}
} else {
SimpleLayout(
modifier
.glideNode(
requestBuilder,
contentDescription,
alignment,
contentScale,
alpha,
colorFilter,
transition,
loadingPlaceholder = loading?.maybePainter(),
errorPlaceholder = failure?.maybePainter(),
)
)
}
}

The modifier that is provided to GlideImage is passed on to both GlideSubcomposition and each of the child composables which causes the duplication. The solution would be to either use the modifier on the GlideSubcomposition OR use it one the child composables.

@sjudd
Copy link
Collaborator

sjudd commented Oct 4, 2023

Thanks, I think your bug is a duplicate of #5272 because I don't see you using GlideSubcomposition or providing a composable placeholder, so you won't hit the codepath in GlideImage you pointed out.

That said, It may still be a bug that the modifier is applied twice, so I'll leave this open. If we do submit #5306, then this will be "fixed" (as in deleted) as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants