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

Coil does not apply contentScale to placeholder/error #2715

Open
vanniktech opened this issue Nov 25, 2024 · 2 comments
Open

Coil does not apply contentScale to placeholder/error #2715

vanniktech opened this issue Nov 25, 2024 · 2 comments
Labels
help wanted Issues that are up for grabs + are good candidates for community PRs

Comments

@vanniktech
Copy link

As you can see in the screenshot (Android) my placeholder (a blur hash image) is correctly shown when using a `1:1 aspect ratio modifier that fills the max width):

Screenshot_20241125_114302

However that same thing on my Mac (Designed for iPad) looks like this:

Screenshot 2024-11-25 at 12 00 07

Essentially the placeholder/error isn't properly scaled with contentScale. I think on Android this works out of the box since Android does the scaling automatically but on iOS this isn't the case, therefore this should be handled universally in coil.

Reproducer: vanniktech/playground#275

If you have any questions please let me know.

@colinrtwhite colinrtwhite added the help wanted Issues that are up for grabs + are good candidates for community PRs label Nov 25, 2024
@colinrtwhite
Copy link
Member

Thanks for the repro project!

but on iOS this isn't the case

Do you have more info about this behaviour? I'd be surprised if this is the case since ContentScale is implemented in common and Coil only uses Painters (no UIImage).

I tried running the repro project, but I get a compiler exception. Have you run into something similar?

e: org.jetbrains.kotlin.backend.common.CompilationException: Back-end: Please report this problem https://kotl.in/issue
/Users/colin/Documents/playground/composeApp/build/generated/sqldelight/code/QueryWrapper/commonMain/app/playground/FooQueries.kt:-1:-1
Details: Internal error in file lowering: java.lang.IllegalStateException: should not be called
        at org.jetbrains.kotlin.utils.addToStdlib.AddToStdlibKt.shouldNotBeCalled(addToStdlib.kt:323)

I recreated a similar situation with a custom ColorPainter with a 100x100 intrinsic size and it worked as expected on Mac and Android. Are you able to repro the issue without the blur hash code?

class ColorPainter(val color: Color) : Painter() {
    private var alpha: Float = 1.0f
    private var colorFilter: ColorFilter? = null

    override val intrinsicSize = Size(100f, 100f)

    override fun DrawScope.onDraw() {
        drawRect(color = color, alpha = alpha, colorFilter = colorFilter)
    }

    override fun applyAlpha(alpha: Float): Boolean {
        this.alpha = alpha
        return true
    }

    override fun applyColorFilter(colorFilter: ColorFilter?): Boolean {
        this.colorFilter = colorFilter
        return true
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is ColorPainter) return false
        if (color != other.color) return false
        return true
    }

    override fun hashCode(): Int {
        return color.hashCode()
    }

    override fun toString(): String {
        return "ColorPainter(color=$color)"
    }
}

AsyncImage(
    model = Unit,
    contentDescription = null,
    contentScale = ContentScale.Fit,
    placeholder = remember { ColorPainter(Color.Red) },
    error = remember { ColorPainter(Color.Red) },
    modifier = Modifier.fillMaxWidth().aspectRatio(1f),
)
Screenshot 2024-11-25 at 12 36 08 AM

@vanniktech
Copy link
Author

Do you have more info about this behaviour?

I just vaguely remember it when I tried to use the same blur hashing in another project natively.

I tried running the repro project, but I get a compiler exception. Have you run into something similar?

Yes, this is known on Jetbrains site and fixed with 2.1.x

What did you run to encounter this? If you run the ios project via xcode through the iosApp.xcodeproj file, it should just compile fine.


I think the fact that I'm using a generated Image and the BitmapPainter is the cause of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that are up for grabs + are good candidates for community PRs
Projects
None yet
Development

No branches or pull requests

2 participants