jordond / kmpalette

🎨 A Compose multiplatform port for Androidx Palette. Generate a color palette from an image.

Home Page:https://demo.kmpalette.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose `Swatch` object to the caller instead of the `Swatch#rgb`

mr3y-the-programmer opened this issue · comments

I'm using androidx.palette in an app and I'm migrating to Kotlin multiplatform. I found this great library, it has everything I need except one small thing.

After generating dominant colors from an ImageBitmap, the API gives the user a way to filter & validate the dominant color by passing Swatch.rgb to isColorValid: (Color) -> Boolean lambda:

.firstOrNull { swatch -> isColorValid(Color(swatch.rgb)) }

but in my use case, I want to validate dominant colors based on Swatch.bodyTextColor:

Color(swatch.bodyTextColor).contrastAgainst(surfaceColor) >= MinContrastRatio // 3f

I think it is more appropriate to expose the Swatch object instead, and let the caller decide how to validate the color based on Swatch properties.

Released in 2.0.0