Skip to content

Commit

Permalink
Fix: constrast, constast, etc --> contrast
Browse files Browse the repository at this point in the history
  • Loading branch information
eneim committed May 29, 2021
1 parent 73d7f25 commit 904a790
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import com.example.jetcaster.ui.theme.JetcasterTheme
import com.example.jetcaster.ui.theme.Keyline1
import com.example.jetcaster.util.DynamicThemePrimaryColorsFromImage
import com.example.jetcaster.util.ToggleFollowPodcastIconButton
import com.example.jetcaster.util.constrastAgainst
import com.example.jetcaster.util.contrastAgainst
import com.example.jetcaster.util.quantityStringResource
import com.example.jetcaster.util.rememberDominantColorState
import com.example.jetcaster.util.verticalGradientScrim
Expand Down Expand Up @@ -149,11 +149,11 @@ fun HomeAppBar(
}

/**
* This is the minimum amount of calculated constrast for a color to be used on top of the
* This is the minimum amount of calculated contrast for a color to be used on top of the
* surface color. These values are defined within the WCAG AA guidelines, and we use a value of
* 3:1 which is the minimum for user-interface components.
*/
private const val MinConstastOfPrimaryVsSurface = 3f
private const val MinContrastOfPrimaryVsSurface = 3f

@OptIn(ExperimentalPagerApi::class) // HorizontalPager is experimental
@Composable
Expand All @@ -173,7 +173,7 @@ fun HomeContent(
val surfaceColor = MaterialTheme.colors.surface
val dominantColorState = rememberDominantColorState { color ->
// We want a color which has sufficient contrast against the surface color
color.constrastAgainst(surfaceColor) >= MinConstastOfPrimaryVsSurface
color.contrastAgainst(surfaceColor) >= MinContrastOfPrimaryVsSurface
}

DynamicThemePrimaryColorsFromImage(dominantColorState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.compose.ui.graphics.luminance
import kotlin.math.max
import kotlin.math.min

fun Color.constrastAgainst(background: Color): Float {
fun Color.contrastAgainst(background: Color): Float {
val fg = if (alpha < 1f) compositeOver(background) else this

val fgLuminance = fg.luminance() + 0.05f
Expand Down

0 comments on commit 904a790

Please sign in to comment.