-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add highcontrast btn in signin page and sync it with server values #92117
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
Changes from all commits
11040f9
7f87a7e
60f88c0
2069610
e8db467
8f50409
d5c3631
818ef0e
85a6f54
bf5e188
a2608a2
6bfeaf0
4e32720
b827473
e9e9da3
6e86a76
8854a3a
f3e8202
fd28842
490dc31
b93685c
239c21f
48de65f
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,53 @@ | ||||
| import React from 'react'; | ||||
| import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; | ||||
| import useLocalize from '@hooks/useLocalize'; | ||||
| import useOnyx from '@hooks/useOnyx'; | ||||
| import useTheme from '@hooks/useTheme'; | ||||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||||
| import {getBaseTheme, getContrastTheme, isHighContrastTheme} from '@styles/theme/utils'; | ||||
| import variables from '@styles/variables'; | ||||
| import {setHighContrastIntent, updateTheme} from '@userActions/User'; | ||||
| import CONST from '@src/CONST'; | ||||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||||
| import Icon from './Icon'; | ||||
| import PressableWithFeedback from './Pressable/PressableWithFeedback'; | ||||
| import Text from './Text'; | ||||
|
|
||||
| function HighContrastModeSwitcher() { | ||||
| const theme = useTheme(); | ||||
| const styles = useThemeStyles(); | ||||
| const {translate} = useLocalize(); | ||||
| const [preferredTheme] = useOnyx(ONYXKEYS.PREFERRED_THEME); | ||||
| const icons = useMemoizedLazyExpensifyIcons(['Moon']); | ||||
|
|
||||
| const currentTheme = preferredTheme ?? CONST.THEME.DEFAULT; | ||||
| const isHighContrast = isHighContrastTheme(currentTheme); | ||||
|
Contributor
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. The button state should be consistent with the UI, which takes the user's intended theme into account: App/src/pages/signin/SignInPage.tsx Line 365 in 48de65f
Fixed via #92978. |
||||
| const label = translate(isHighContrast ? 'themePage.disableHighContrast' : 'themePage.enableHighContrast'); | ||||
|
|
||||
| const toggleHighContrast = () => { | ||||
| const baseTheme = getBaseTheme(currentTheme); | ||||
| updateTheme(isHighContrast ? baseTheme : getContrastTheme(baseTheme), false); | ||||
| setHighContrastIntent(!isHighContrast); | ||||
| }; | ||||
|
rushatgabhane marked this conversation as resolved.
|
||||
|
|
||||
| return ( | ||||
| <PressableWithFeedback | ||||
| onPress={toggleHighContrast} | ||||
| sentryLabel={CONST.SENTRY_LABEL.HIGH_CONTRAST_MODE_SWITCHER.TOGGLE} | ||||
| role={CONST.ROLE.BUTTON} | ||||
|
Contributor
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. I think the role of this element is incorrect here, since it's essentially a Switch(
Member
Author
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. @MelvinBot according to wcag 2.2 what is the correct role here
Contributor
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. @/tmp/melvinbot-response.md
Member
Author
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. I agree with you. But if we change it to switch role, then we'll have to add a visual indicator for the switch - to indicate on/off state 😓
Contributor
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. All right, I think we can leave it as is, but I'm not sure if we need |
||||
| accessibilityLabel={label} | ||||
| style={[styles.flexRow, styles.alignItemsCenter]} | ||||
| > | ||||
| <Icon | ||||
| src={icons.Moon} | ||||
| fill={theme.icon} | ||||
| width={variables.iconSizeSmall} | ||||
| height={variables.iconSizeSmall} | ||||
| accessibilityLabel={label} | ||||
| /> | ||||
| <Text style={[styles.textSmall, styles.ml2]}>{label}</Text> | ||||
| </PressableWithFeedback> | ||||
| ); | ||||
| } | ||||
|
|
||||
| export default HighContrastModeSwitcher; | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import {useEffect, useRef} from 'react'; | ||
| import {getBaseTheme, getContrastTheme} from '@styles/theme/utils'; | ||
| import {setHighContrastIntent, updateTheme} from '@userActions/User'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Reconcile a logged-out user's high contrast choice from the sign-in page with the base theme the server returns once they sign in. | ||
| * The intent is `true` when they enabled it, `false` when they disabled it, and cleared when there is nothing to reconcile. | ||
| */ | ||
| function useReconcileHighContrastIntent() { | ||
| const [preferredTheme] = useOnyx(ONYXKEYS.PREFERRED_THEME); | ||
| const [highContrastIntent] = useOnyx(ONYXKEYS.SIGN_IN_HIGH_CONTRAST_INTENT); | ||
| const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP); | ||
| const [session] = useOnyx(ONYXKEYS.SESSION); | ||
| const wasLoadingApp = useRef<boolean | undefined>(undefined); | ||
|
|
||
| useEffect(() => { | ||
| const hasFinishedLoading = !!wasLoadingApp.current && !isLoadingApp; | ||
| wasLoadingApp.current = isLoadingApp; | ||
| if (!hasFinishedLoading || highContrastIntent === undefined || !session?.authToken) { | ||
| return; | ||
| } | ||
| const currentTheme = preferredTheme ?? CONST.THEME.DEFAULT; | ||
| const baseTheme = getBaseTheme(currentTheme); | ||
| const targetTheme = highContrastIntent ? getContrastTheme(baseTheme) : baseTheme; | ||
| if (currentTheme !== targetTheme) { | ||
| updateTheme(targetTheme, false); | ||
| } | ||
| setHighContrastIntent(null); | ||
| }, [isLoadingApp, highContrastIntent, preferredTheme, session?.authToken]); | ||
| } | ||
|
|
||
| export default useReconcileHighContrastIntent; |
Uh oh!
There was an error while loading. Please reload this page.