-
Notifications
You must be signed in to change notification settings - Fork 52
Fix accessibility bugs for New Arch Gallery - Dark mode and High Contrast theme support #653
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: main
Are you sure you want to change the base?
Changes from all commits
202f0d5
e3c0fab
c070af1
7df2bca
911c848
83707a9
49f2ddc
9b511a3
ce63cb0
356cacc
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 |
---|---|---|
|
@@ -9,6 +9,23 @@ import { | |
useAnimatedValue, | ||
} from 'react-native'; | ||
import type { PropsWithChildren } from 'react'; | ||
import { ThemeContext } from './themes/Theme'; | ||
import LightTheme from './themes/LightTheme'; | ||
import DarkTheme from './themes/DarkTheme'; | ||
import HighContrastTheme from './themes/HighContrastTheme'; | ||
import useHighContrastState from './hooks/useHighContrastState'; | ||
|
||
type Theme = { | ||
dark: boolean; | ||
colors: { | ||
primary: string; | ||
background: string; | ||
card: string; | ||
text: string; | ||
border: string; | ||
notification: string; | ||
}; | ||
}; | ||
|
||
type NavigationAction = { | ||
type: string, | ||
|
@@ -42,8 +59,10 @@ type RouteType = { | |
params: any, | ||
} | ||
|
||
type NavigationContainerProps = PropsWithChildren<{}>; | ||
const NavigationContainer = ({children}: NavigationContainerProps) => { | ||
type NavigationContainerProps = PropsWithChildren<{ | ||
theme?: Theme; | ||
}>; | ||
const NavigationContainer = ({children, theme}: NavigationContainerProps) => { | ||
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. @copilot I'm confused about the mix of a Context-style theme, and a pass through by prop theme. All while App.tsx has two other Theme contexts. Why the change to theme design here? These seems like more and I'm not sure why it doesn't blend with what's already there. Can you clarify the design? Why are you creating new theme objects and types when there are already ones in src\themes and also referred to in this app's App.tsx? 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. You're absolutely right to question this design. I made an architectural mistake by creating a new theme system instead of using the existing one. The app already has proper theme contexts in The issue was that the original This creates unnecessary complexity and doesn't integrate with the existing theme architecture. Would you like me to refactor this to use the existing theme system properly instead? 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. @copilot yes please refactor 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. Refactored the Navigation.tsx in commit 9b511a3 to properly integrate with the existing theme system instead of creating a new one. Key changes:
The solution now properly uses the established theme architecture without duplicating systems. 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. @copilot dont you need to do any changes in src/theme only? 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. You're right to question this. Looking at the original The current approach works since:
But you're correct that it would be cleaner to use the standard 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. @copilot use existing code and dont add new theme objects in navigation 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. Updated in commit ce63cb0 to use the existing theme system without adding new theme objects to Navigation.tsx. Changes made:
The solution now uses the standard React Navigation theme approach throughout. |
||
const [currentScreen, setCurrentScreen] = useState('Home'); | ||
const [routes, setRoutes] = useState<RouteType[]>([{name: 'Home', key: 'Home', params: {}}]); | ||
const [parameters, setParameters] = useState({} as any); | ||
|
@@ -324,14 +343,20 @@ const useIsFocused = () => { | |
}; | ||
|
||
const useTheme = () => { | ||
return {colors: { | ||
primary: '#0066cc', | ||
background: '#FFFFFF', | ||
card: '#FFFFFF', | ||
text: '#505050', | ||
border: '#E6E6E6', | ||
notification: 'rgb(255, 59, 48)', | ||
}}; | ||
const themeMode = React.useContext(ThemeContext); | ||
const isHighContrast = useHighContrastState(); | ||
|
||
// Return the appropriate theme based on the context and high contrast state | ||
if (isHighContrast) { | ||
return HighContrastTheme; | ||
} | ||
|
||
if (themeMode === 'dark') { | ||
return DarkTheme; | ||
} | ||
|
||
// Default to light theme | ||
return LightTheme; | ||
}; | ||
|
||
const Theme = { | ||
|
@@ -358,3 +383,4 @@ const DrawerActions = { | |
}; | ||
|
||
export { NavigationContainer, StackNavigator, StackScreen, createNativeStackNavigator, createDrawerNavigator, getDrawerStatusFromState, useIsFocused, useTheme, Theme, useNavigation, DrawerActions }; | ||
export type { Theme }; |
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.
@copilot nit: Why the convention of calling the theme "colors" and not "theme"?
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.
The
useTheme()
hook returns a theme object with acolors
property, so I destructure{colors}
from the theme to pass just the colors to the style functions. This follows the pattern used in other components in the codebase. However, you're right that it could be clearer - I could use{colors}
fromuseTheme()
directly in the component or rename the parameter to be more explicit about what it represents.