fix(filter-chip,suggestion-chip): support a11y high contrast mode on chip components#1195
fix(filter-chip,suggestion-chip): support a11y high contrast mode on chip components#1195
Conversation
🟢 Netlify deploy for commit 692fe97 succeededDeploy preview: https://69d75b5b727936420d83b408--ouds-android.netlify.app |
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.tooling.preview.PreviewParameter | ||
| import com.orange.ouds.core.component.OudsFilterChip |
There was a problem hiding this comment.
These two new imports are unused.
|
|
||
| @Composable | ||
| override fun Preview(theme: OudsThemeContract, darkThemeEnabled: Boolean, highContrastModeEnabled: Boolean, parameter: Any?) { | ||
| @Suppress("UNCHECKED_CAST") |
There was a problem hiding this comment.
This annotation is not necessary because there is no preview parameter.
There was a problem hiding this comment.
I wonder if high contrast is correct for Sosh since I find that the white tick is easier to read compared to the black one. What do you think?
The same comment applies to the Wireframe theme.
| }.value | ||
| OudsChipState.Enabled -> when { | ||
| // In order to reach the a11y AAA level, when high contrast mode is enabled, the enabled chip border color must use `color.content.default` token | ||
| LocalHighContrastModeEnabled.current -> OudsTheme.colorScheme.content.default |
There was a problem hiding this comment.
We can use this PR to update the isHighContrastModeEnabled method in ContextExt.kt since a new API is available with API level 36 (I also removed @SuppressLint("DiscouragedPrivateApi") which does not seem useful):
@SuppressLint("PrivateApi")
internal fun Context.isHighContrastModeEnabled(): Boolean {
val accessibilityManager = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) {
accessibilityManager.isHighContrastTextEnabled
} else {
with(accessibilityManager) {
// Workaround to access mIsHighTextContrastEnabled field because it is hidden with a @UnsupportedAppUsage annotation
// On some OS versions this field is named mIsHighContrastTextEnabled
tryOrNull { javaClass.getDeclaredField("mIsHighTextContrastEnabled") }
.orElse { tryOrNull { javaClass.getDeclaredField("mIsHighContrastTextEnabled") } }
?.also { it.isAccessible = true }
?.getBoolean(this)
.orElse { false }
}
}
}There is also a bug with this method because the app needs to be restarted in order to take the new accessibility setting into account. We can probably open a bug and check this later.
| OudsChipState.Pressed -> colorContentSelectedPressed | ||
| OudsChipState.Disabled -> colorContentSelectedDisabled | ||
| }.value | ||
| OudsChipState.Enabled -> if (LocalHighContrastModeEnabled.current) OudsTheme.colorScheme.content.default else colorContentSelectedTickEnabled.value |
There was a problem hiding this comment.
Rules for the high contrast mode in chips seems different from the high contrast mode in controls. Do you know where I can find them?
a75b4c8 to
d42deab
Compare
No description provided.