mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix: preserve Electric contrast for filled and text buttons (#1149)
This commit is contained in:
1 parent
2457f27cdf
commit
746a850a44
4 files changed
+88
-4
No files matched your search
@@ -185,10 +185,9 @@ internal fun PrimaryButton(
|
||||
.graphicsLayer { alpha = if (LaunchOrigin.flooding === placed) 0f else 1f; scaleX = scale; scaleY = scale; shadowElevation = if (enabled) lift.dp.toPx() else 0f; shape = Shape12; clip = false; ambientShadowColor = pal.signal; spotShadowColor = pal.signal }
|
||||
.clip(Shape12)
|
||||
.background(if (enabled) Brush.linearGradient(listOf(colors.primary, pal.primary2)) else Brush.linearGradient(listOf(colors.surfaceVariant, colors.surfaceVariant)))
|
||||
.shine(hot, 0.45f)
|
||||
.then(if (enabled) Modifier else Modifier.border(1.dp, pal.line2, Shape12))
|
||||
.glideBorder(hot, Shape12, pal.signal)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled) {
|
||||
.then(if (hot) Modifier.border(2.dp, pal.signal, Shape12) else Modifier)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = null, enabled = enabled) {
|
||||
placed[0]?.takeIf { it.isAttached }?.let { LaunchOrigin.mark(it.boundsInRoot(), placed) }
|
||||
onClick()
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ object Themes {
|
||||
ELECTRIC, R.string.theme_electric, R.string.theme_electric_detail,
|
||||
background = Color(0xFF070A10), surface = Color(0xFF0F1522), surfaceVariant = Color(0xFF16203A), line = Color(0xFF1E2A47), line2 = Color(0xFF2A3A5E),
|
||||
onBackground = Color(0xFFEEF3FF), onSurfaceVariant = Color(0xFF8B9AB8),
|
||||
primary = Color(0xFF2E86FF), primary2 = Color(0xFF136CE0), onPrimary = Color(0xFFFFFFFF), signal = Color(0xFF2E86FF),
|
||||
primary = Color(0xFF2E86FF), primary2 = Color(0xFF2684FF), onPrimary = Color(0xFF03111F), signal = Color(0xFF2E86FF),
|
||||
good = Color(0xFF4CD37F),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class PrimaryButtonContrastTest {
|
||||
@Test fun electricTextButtonsRemainReadableOnPageAndDialogSurfaces() {
|
||||
val palette = Themes.byId(Themes.ELECTRIC)
|
||||
for (background in listOf(palette.background, palette.surface)) {
|
||||
assertTrue("Electric text button: ${contrast(palette.primary, background)}",
|
||||
contrast(palette.primary, background) >= 4.5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun normalSizedPrimaryTextMeetsContrastAcrossEveryThemeGradient() {
|
||||
for (palette in Themes.all) {
|
||||
for (step in 0..100) {
|
||||
val fraction = step / 100f
|
||||
val start = palette.primary
|
||||
val end = palette.primary2
|
||||
val background = Color(
|
||||
start.red + (end.red - start.red) * fraction,
|
||||
start.green + (end.green - start.green) * fraction,
|
||||
start.blue + (end.blue - start.blue) * fraction,
|
||||
)
|
||||
val ratio = contrast(palette.onPrimary, background)
|
||||
assertTrue("${palette.id} gradient $step: $ratio", ratio >= 4.5f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun contrast(a: Color, b: Color): Float {
|
||||
val light = maxOf(a.luminance(), b.luminance())
|
||||
val dark = minOf(a.luminance(), b.luminance())
|
||||
return (light + 0.05f) / (dark + 0.05f)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.semantics.SemanticsActions
|
||||
import androidx.compose.ui.test.assertIsFocused
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performSemanticsAction
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
class PrimaryButtonFocusContrastTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
@Test fun focusedPrimaryButtonDoesNotClaimAColorOverlayAboveItsLabel() {
|
||||
lateinit var glide: FocusGlide
|
||||
var clicks = 0
|
||||
compose.setContent {
|
||||
val view = LocalView.current
|
||||
glide = remember(view) { FocusGlide(view) }
|
||||
DroidDeckTheme(Themes.ELECTRIC) {
|
||||
CompositionLocalProvider(LocalFocusGlide provides glide) {
|
||||
PrimaryButton("Play") { clicks++ }
|
||||
}
|
||||
}
|
||||
}
|
||||
val button = compose.onNodeWithText("Play")
|
||||
button.performSemanticsAction(SemanticsActions.RequestFocus)
|
||||
button.assertIsFocused()
|
||||
compose.runOnIdle { assertNull(glide.current) }
|
||||
button.performClick()
|
||||
compose.runOnIdle {
|
||||
assertEquals(1, clicks)
|
||||
assertNull(glide.current)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user