forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
60 lines (51 loc) · 1.39 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* @flow */
import Expo, { KeepAwake } from 'expo';
import * as React from 'react';
import { StatusBar } from 'react-native';
import {
Provider as PaperProvider,
DarkTheme,
DefaultTheme,
} from 'react-native-paper';
import createReactContext from 'create-react-context';
import { DrawerNavigator } from 'react-navigation';
import RootNavigator from './src/RootNavigator';
import DrawerItems from './DrawerItems';
import type { Theme } from 'react-native-paper/types';
type State = {
theme: Theme,
};
const ThemeToggleContext: any = createReactContext();
const App = DrawerNavigator(
{ Home: { screen: RootNavigator } },
{
contentComponent: () => (
<ThemeToggleContext.Consumer>
{toggleTheme => <DrawerItems toggleTheme={toggleTheme} />}
</ThemeToggleContext.Consumer>
),
}
);
class PaperExample extends React.Component<{}, State> {
state = {
theme: DefaultTheme,
};
componentDidMount() {
StatusBar.setBarStyle('light-content');
}
_toggleTheme = () =>
this.setState(state => ({
theme: state.theme === DarkTheme ? DefaultTheme : DarkTheme,
}));
render() {
return (
<PaperProvider theme={this.state.theme}>
<ThemeToggleContext.Provider value={this._toggleTheme}>
<App />
</ThemeToggleContext.Provider>
<KeepAwake />
</PaperProvider>
);
}
}
Expo.registerRootComponent(PaperExample);