File tree 6 files changed +52
-15
lines changed
android/app/src/main/java/com/rnmagentographql 6 files changed +52
-15
lines changed Original file line number Diff line number Diff line change
1
+ export * from 'react-native-appearance/src/mock' ;
Original file line number Diff line number Diff line change 1
1
package com .rnmagentographql ;
2
2
3
3
import com .facebook .react .ReactActivity ;
4
+ import android .content .Intent ;
5
+ import android .content .res .Configuration ;
4
6
5
7
public class MainActivity extends ReactActivity {
6
8
@@ -12,4 +14,12 @@ public class MainActivity extends ReactActivity {
12
14
protected String getMainComponentName () {
13
15
return "RNMagentoGraphQL" ;
14
16
}
17
+
18
+ @ Override
19
+ public void onConfigurationChanged (Configuration newConfig ) {
20
+ super .onConfigurationChanged (newConfig );
21
+ Intent intent = new Intent ("onConfigurationChanged" );
22
+ intent .putExtra ("newConfig" , newConfig );
23
+ sendBroadcast (intent );
24
+ }
15
25
}
Original file line number Diff line number Diff line change 26
26
"i18n-js" : " ^3.8.0" ,
27
27
"react" : " 16.13.1" ,
28
28
"react-native" : " 0.63.3" ,
29
+ "react-native-appearance" : " ^0.3.4" ,
29
30
"react-native-elements" : " ^3.0.1" ,
30
31
"react-native-gesture-handler" : " ^1.9.0" ,
31
32
"react-native-localize" : " ^2.0.1" ,
Original file line number Diff line number Diff line change 1
1
import React , { useEffect , useState } from 'react' ;
2
+ import { Appearance , AppearanceProvider } from 'react-native-appearance' ;
2
3
import { ThemeProvider } from 'react-native-elements' ;
3
4
import { OverflowMenuProvider } from 'react-navigation-header-buttons' ;
4
5
import Navigator from './navigation' ;
@@ -8,22 +9,36 @@ import { theme } from './theme';
8
9
import { Spinner } from './components' ;
9
10
10
11
const App = ( ) : React . ReactElement => {
12
+ const [ colorScheme , setColorScheme ] = useState ( 'light' ) ;
11
13
const [ client , setClient ] = useState < ApolloClient < any > > ( ) ;
12
14
15
+ console . log ( colorScheme ) ;
16
+
13
17
useEffect ( ( ) => {
14
18
getApolloClient ( )
15
19
. then ( setClient )
16
20
. catch ( e => console . log ( e ) ) ;
21
+
22
+ const subscription = Appearance . addChangeListener (
23
+ ( { colorScheme : newColorScheme } ) => {
24
+ // do something with color scheme
25
+ setColorScheme ( newColorScheme ) ;
26
+ } ,
27
+ ) ;
28
+
29
+ return ( ) => subscription . remove ( ) ;
17
30
} , [ ] ) ;
18
31
19
32
if ( client ) {
20
33
return (
21
34
< ApolloProvider client = { client } >
22
- < ThemeProvider theme = { theme } >
23
- < OverflowMenuProvider >
24
- < Navigator />
25
- </ OverflowMenuProvider >
26
- </ ThemeProvider >
35
+ < AppearanceProvider >
36
+ < ThemeProvider useDark = { colorScheme === 'dark' } >
37
+ < OverflowMenuProvider >
38
+ < Navigator />
39
+ </ OverflowMenuProvider >
40
+ </ ThemeProvider >
41
+ </ AppearanceProvider >
27
42
</ ApolloProvider >
28
43
) ;
29
44
}
Original file line number Diff line number Diff line change @@ -6,16 +6,20 @@ import {
6
6
HeaderButtonProps ,
7
7
HeaderButtonsProps ,
8
8
} from 'react-navigation-header-buttons' ;
9
+ import { useTheme } from '@react-navigation/native' ;
9
10
10
11
// define IconComponent, color, sizes and OverflowIcon in one place
11
- const CustomHeaderButton = ( props : HeaderButtonProps ) => (
12
- < HeaderButton
13
- IconComponent = { MaterialIcons }
14
- iconSize = { 23 }
15
- color = "black"
16
- { ...props }
17
- />
18
- ) ;
12
+ const CustomHeaderButton = ( props : HeaderButtonProps ) => {
13
+ const { colors } = useTheme ( ) ;
14
+ return (
15
+ < HeaderButton
16
+ IconComponent = { MaterialIcons }
17
+ iconSize = { 23 }
18
+ color = { colors . text }
19
+ { ...props }
20
+ />
21
+ ) ;
22
+ } ;
19
23
20
24
export const CustomHeaderButtons = ( props : HeaderButtonsProps ) => {
21
25
return (
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
- import { NavigationContainer } from '@react-navigation/native' ;
2
+ import {
3
+ DarkTheme ,
4
+ DefaultTheme ,
5
+ NavigationContainer ,
6
+ } from '@react-navigation/native' ;
3
7
import { createDrawerNavigator } from '@react-navigation/drawer' ;
8
+ import { useColorScheme } from 'react-native-appearance' ;
4
9
import StackNavigator from './StackNavigator' ;
5
10
import { DrawerScreen } from '../screens' ;
6
11
import { useCart } from '../logic/cart/useCart' ;
7
12
8
13
const Drawer = createDrawerNavigator ( ) ;
9
14
10
15
const RootNavigator = ( ) => {
16
+ const scheme = useColorScheme ( ) ;
11
17
const { cartId } = useCart ( ) ;
12
18
return (
13
- < NavigationContainer >
19
+ < NavigationContainer theme = { scheme === 'dark' ? DarkTheme : DefaultTheme } >
14
20
< Drawer . Navigator drawerContent = { props => < DrawerScreen { ...props } /> } >
15
21
< Drawer . Screen
16
22
name = "drawer"
You can’t perform that action at this time.
0 commit comments