@@ -6,9 +6,15 @@ import type {
66 NavigationNavigator ,
77 NavigationScreenProp ,
88 NavigationNavigatorProps ,
9+ SupportedThemes ,
910} from '@react-navigation/core' ;
1011
1112import * as React from 'react' ;
13+ import { SafeAreaProvider } from 'react-native-safe-area-context' ;
14+ import {
15+ ThemeProvider ,
16+ NavigationProvider ,
17+ } from '@react-navigation/core' ;
1218
1319import {
1420 initializeListeners ,
@@ -35,6 +41,7 @@ function createReduxContainer<
3541 ContainerProps: {
3642 ...$Diff < NavigatorProps , InjectedProps < State >> ,
3743 ...$Exact < RequiredProps < State >> ,
44+ theme : SupportedThemes | 'no-preference' ,
3845 } ,
3946> (
4047 Navigator : NavigatorType ,
@@ -47,6 +54,7 @@ function createReduxContainer<
4754
4855 static router = Navigator . router ;
4956 currentNavProp : ?NavigationScreenProp < State > ;
57+ static defaultProps = { theme : 'no-preference' } ;
5058
5159 componentDidMount ( ) {
5260 initializeListeners ( key , this . props . state ) ;
@@ -60,6 +68,21 @@ function createReduxContainer<
6068 return this . currentNavProp ;
6169 }
6270
71+ get theme ( ) {
72+ if ( this . props . theme === 'light' || this . props . theme === 'dark' ) {
73+ return this . props . theme ;
74+ } else if ( this . props . theme === 'no-preference' ) {
75+ return 'light' ;
76+ } else {
77+ console . warn (
78+ `Invalid theme provided: ${
79+ this . props . theme
80+ } . Only 'light' and 'dark' are supported. Falling back to 'light'`
81+ ) ;
82+ return 'light' ;
83+ }
84+ }
85+
6386 render ( ) {
6487 const { dispatch , state , ...props } = this . props ;
6588 this . currentNavProp = propConstructor (
@@ -69,10 +92,16 @@ function createReduxContainer<
6992 this . getCurrentNavigation ,
7093 ) ;
7194 return (
72- < Navigator
73- { ...props }
74- navigation = { this . currentNavProp }
75- />
95+ < SafeAreaProvider >
96+ < ThemeProvider value = { this . theme } >
97+ < NavigationProvider value = { this . currentNavProp } >
98+ < Navigator
99+ { ...props }
100+ navigation = { this . currentNavProp }
101+ />
102+ </ NavigationProvider >
103+ </ ThemeProvider >
104+ </ SafeAreaProvider >
76105 ) ;
77106 }
78107
0 commit comments