ColorUtils

object ColorUtils

Utility functions for color operations and contrast checking.

Functions

Link copied to clipboard
fun calculateContrastRatio(color1: Color, color2: Color): Double

Calculates the contrast ratio between two colors.

Link copied to clipboard

Calculates the relative luminance of a color using the WCAG formula.

Link copied to clipboard
fun generateSubtleShade(baseColor: Color, amount: Float = 0.08f): Color

Generates a subtle shade of the given color. If the color is bright (light), returns a slightly darker shade. If the color is dark, returns a slightly lighter shade.

Link copied to clipboard
fun hasSufficientContrast(color1: Color, color2: Color, minimumRatio: Double = 4.5): Boolean

Checks if two colors have sufficient contrast for accessibility.

Link copied to clipboard

Determines if a color is bright (light) or dark based on its luminance.

Link copied to clipboard
fun readableShadowColor(backgroundColor: Color): Color

Returns an appropriate shadow color based on background brightness.

Link copied to clipboard
fun readableTextColor(backgroundColor: Color, lightColor: Color = Color.White, darkColor: Color = Color.Black): Color

Returns an appropriate contrast color (light or dark) based on background color. Similar to iOS UIColor.readableTextColor()