@@ -54,33 +54,21 @@ type Theme = {
5454 } ;
5555} ;
5656
57- // Default theme colors constant to avoid duplication
58- const DEFAULT_THEME_COLORS = {
59- primary : '#0066cc' ,
60- background : '#FFFFFF' ,
61- card : '#FFFFFF' ,
62- text : '#505050' ,
63- border : '#E6E6E6' ,
64- notification : 'rgb(255, 59, 48)' ,
65- } ;
66-
67- const DEFAULT_THEME : Theme = {
68- dark : false ,
69- colors : DEFAULT_THEME_COLORS ,
70- } ;
71-
7257type NavigationContainerProps = PropsWithChildren < {
7358 theme ?: Theme ;
7459} > ;
7560
76- // Create a theme context
77- const ThemeContext = React . createContext < Theme > ( DEFAULT_THEME ) ;
61+ // Store the current theme in a context for useTheme hook
62+ let currentTheme : Theme | null = null ;
7863
7964const NavigationContainer = ( { children, theme} : NavigationContainerProps ) => {
8065 const [ currentScreen , setCurrentScreen ] = useState ( 'Home' ) ;
8166 const [ routes , setRoutes ] = useState < RouteType [ ] > ( [ { name : 'Home' , key : 'Home' , params : { } } ] ) ;
8267 const [ parameters , setParameters ] = useState ( { } as any ) ;
8368
69+ // Store the theme for useTheme hook
70+ currentTheme = theme || null ;
71+
8472 const navigationContext = {
8573 push : ( screen : string , parameters : any , _navigateFrom : string ) => {
8674 setRoutes ( [ ...routes , { name : screen , key : screen , params : parameters } ] ) ;
@@ -107,14 +95,11 @@ const NavigationContainer = ({children, theme}: NavigationContainerProps) => {
10795 routes : routes ,
10896 parameters : parameters ,
10997 } ;
110- const currentTheme = theme || DEFAULT_THEME ;
11198
11299 return (
113- < ThemeContext . Provider value = { currentTheme } >
114- < NavigationContext . Provider value = { navigationContext } >
115- { children }
116- </ NavigationContext . Provider >
117- </ ThemeContext . Provider >
100+ < NavigationContext . Provider value = { navigationContext } >
101+ { children }
102+ </ NavigationContext . Provider >
118103 ) ;
119104} ;
120105
@@ -361,19 +346,23 @@ const useIsFocused = () => {
361346} ;
362347
363348const useTheme = ( ) => {
364- return React . useContext ( ThemeContext ) ;
365- } ;
366-
367- const Theme = {
368- colors : {
369- primary : '#0066cc' ,
370- background : '#FFFFFF' ,
371- card : '#FFFFFF' ,
372- text : '#505050' ,
373- border : '#E6E6E6' ,
374- notification : 'rgb(255, 59, 48)' ,
375- } ,
376- dark : false ,
349+ // Return the current theme passed to NavigationContainer, or fallback to default light theme colors
350+ if ( currentTheme ) {
351+ return currentTheme ;
352+ }
353+
354+ // Fallback to default light theme if no theme was provided
355+ return {
356+ dark : false ,
357+ colors : {
358+ primary : '#0066cc' ,
359+ background : '#FFFFFF' ,
360+ card : '#FFFFFF' ,
361+ text : '#505050' ,
362+ border : '#E6E6E6' ,
363+ notification : 'rgb(255, 59, 48)' ,
364+ } ,
365+ } ;
377366} ;
378367
379368const useNavigation = ( ) => {
@@ -387,5 +376,5 @@ const DrawerActions = {
387376 toggleDrawer : ( ) => { console . log ( 'toggleDrawer' ) ; return { type : 'TOGGLE_DRAWER' } ; } ,
388377} ;
389378
390- export { NavigationContainer , StackNavigator , StackScreen , createNativeStackNavigator , createDrawerNavigator , getDrawerStatusFromState , useIsFocused , useTheme , Theme , useNavigation , DrawerActions } ;
379+ export { NavigationContainer , StackNavigator , StackScreen , createNativeStackNavigator , createDrawerNavigator , getDrawerStatusFromState , useIsFocused , useTheme , useNavigation , DrawerActions } ;
391380export type { Theme } ;
0 commit comments