feat: add high-contrast theme with accessible message bubbles (#5135)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
James Rich 2026-04-14 20:14:20 -05:00 committed by GitHub
parent f48fc61729
commit fa63a4ac50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 328 additions and 65 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.theme
import androidx.compose.runtime.staticCompositionLocalOf
/**
* Application-wide contrast level for accessibility.
*
* [STANDARD] keeps the default Material 3 color scheme. [MEDIUM] uses Material 3 medium-contrast color tokens and
* increases message bubble opacity. [HIGH] uses Material 3 high-contrast color tokens, forces `onSurface` text in
* message bubbles, and replaces translucent node-color fills with opaque theme surfaces plus accent borders.
*/
enum class ContrastLevel(val value: Int) {
STANDARD(0),
MEDIUM(1),
HIGH(2),
;
companion object {
fun fromValue(value: Int): ContrastLevel = entries.firstOrNull { it.value == value } ?: STANDARD
}
}
/**
* Composition local providing the current [ContrastLevel].
*
* Read by components that need to adapt their rendering for accessibility (e.g. message bubbles, signal indicators).
*/
val LocalContrastLevel = staticCompositionLocalOf { ContrastLevel.STANDARD }

View file

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
@file:Suppress("UnusedPrivateProperty")
@file:Suppress("MatchingDeclarationName")
package org.meshtastic.core.ui.theme
@ -25,6 +25,7 @@ import androidx.compose.material3.MotionScheme.Companion.expressive
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
@ -272,19 +273,33 @@ val unspecified_scheme = ColorFamily(Color.Unspecified, Color.Unspecified, Color
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = true,
contrastLevel: ContrastLevel = ContrastLevel.STANDARD,
content:
@Composable()
() -> Unit,
) {
val dynamicScheme = if (dynamicColor) dynamicColorScheme(darkTheme) else null
val colorScheme = dynamicScheme ?: if (darkTheme) darkScheme else lightScheme
val dynamicScheme =
if (dynamicColor && contrastLevel == ContrastLevel.STANDARD) {
dynamicColorScheme(darkTheme)
} else {
null
}
val colorScheme =
dynamicScheme
?: when (contrastLevel) {
ContrastLevel.MEDIUM -> if (darkTheme) mediumContrastDarkColorScheme else mediumContrastLightColorScheme
ContrastLevel.HIGH -> if (darkTheme) highContrastDarkColorScheme else highContrastLightColorScheme
else -> if (darkTheme) darkScheme else lightScheme
}
MaterialExpressiveTheme(
colorScheme = colorScheme,
typography = AppTypography,
motionScheme = expressive(),
content = content,
)
CompositionLocalProvider(LocalContrastLevel provides contrastLevel) {
MaterialExpressiveTheme(
colorScheme = colorScheme,
typography = AppTypography,
motionScheme = expressive(),
content = content,
)
}
}
const val MODE_DYNAMIC = 6969420

View file

@ -118,6 +118,7 @@ class UIViewModel(
}
val theme: StateFlow<Int> = uiPrefs.theme
val contrastLevel: StateFlow<Int> = uiPrefs.contrastLevel
val firmwareEdition = meshLogRepository.getMyNodeInfo().map { nodeInfo -> nodeInfo?.firmware_edition }