-
Notifications
You must be signed in to change notification settings - Fork 4
fix(filter-chip,suggestion-chip): support a11y high contrast mode on chip components #1195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
325124d
604de2a
3c6f3c7
1d764bd
2de7569
a8ad1e9
3ec173c
fcc2392
f598919
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Software Name: OUDS Android | ||
| * SPDX-FileCopyrightText: Copyright (c) Orange SA | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * This software is distributed under the MIT license, | ||
| * the text of which is available at https://opensource.org/license/MIT/ | ||
| * or see the "LICENSE" file for more details. | ||
| * | ||
| * Software description: Android library of reusable graphical components | ||
| */ | ||
|
|
||
| package com.orange.ouds.core.extensions | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.graphics.compositeOver | ||
| import androidx.compose.ui.graphics.luminance | ||
| import com.orange.ouds.core.theme.LocalHighContrastModeEnabled | ||
| import com.orange.ouds.core.theme.OudsTheme | ||
|
|
||
| /** | ||
| * Returns a high contrasted color for better contrast when high contrast mode is enabled. | ||
| * | ||
| * When high contrast mode is disabled, the original color is returned unchanged. | ||
| * | ||
| * @param background The background color on which this color will be displayed. | ||
| * If transparent, the theme's primary background color is used as reference. | ||
| * @return `OudsTheme.colorScheme.always.black` or `OudsTheme.colorScheme.always.white` color when high contrast mode is enabled, or the original color otherwise. | ||
| */ | ||
| @Composable | ||
| fun Color.highContrasted(background: Color = Color.Transparent): Color { | ||
| if (!LocalHighContrastModeEnabled.current) return this | ||
|
|
||
| // Composite the background over primary background color to handle transparency | ||
| val effectiveBackground = background.compositeOver(OudsTheme.colorScheme.background.primary) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am correct, this line makes the assumption that the background color of the app is always background primary. Are we sure about that? |
||
|
|
||
| // Composite the current color over background to handle transparency | ||
| val effectiveColor = compositeOver(effectiveBackground) | ||
|
|
||
| // Return the best contrast color for the current color | ||
| return if (effectiveColor.luminance() < 0.3f) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does |
||
| OudsTheme.colorScheme.always.black | ||
| } else { | ||
| OudsTheme.colorScheme.always.white | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method be internal?