-
Notifications
You must be signed in to change notification settings - Fork 5
/
App.js
101 lines (86 loc) · 2.76 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'react-native-gesture-handler';
import bugsnag from '@bugsnag/expo';
import React from 'react';
import { Platform, StatusBar } from 'react-native';
import { ThemeProvider } from 'styled-components';
import * as Font from 'expo-font';
import * as Icon from '@expo/vector-icons';
import { AppLoading } from 'expo';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import FlashMessage from 'react-native-flash-message';
import theme, { ThemeContext } from './config/theme';
import AppNavigator from './navigation/AppNavigator';
import ErrorFallback from './components/ErrorFallback';
const bugsnagClient = bugsnag();
const ErrorBoundary = bugsnagClient.getPlugin('react');
const _makeTheme = (type = 'light') => ({
...theme(type),
});
const dark = _makeTheme('dark');
const light = _makeTheme('light');
export default class App extends React.PureComponent {
state = {
isLoadingComplete: false,
theme: 'light',
};
componentDidMount() {
this._changeStatusBarStyle();
}
toggleTheme = () => {
this.setState(
({ theme }) => ({
theme: theme === 'light' ? 'dark' : 'light',
}),
this._changeStatusBarStyle
);
};
_changeStatusBarStyle = () => {
StatusBar.setBarStyle(
this.state.theme === 'light' ? 'dark-content' : 'light-content'
);
};
_loadResourcesAsync = async () =>
Promise.all([
Font.loadAsync({
// This is the font that we are using for our tab bar
...Icon.Ionicons.font,
// Feel free to remove this if you are not using it in your app
'open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf'),
'open-sans-regular': require('./assets/fonts/OpenSans-Regular.ttf'),
}),
]);
_handleLoadingError = error => {
// In this case, you might want to report the error to your error
// reporting service, for example Sentry
bugsnagClient.notify(error);
};
_handleFinishLoading = () => {
this.setState({ isLoadingComplete: true });
};
render() {
const { isLoadingComplete } = this.state;
if (!isLoadingComplete) {
return (
<AppLoading
startAsync={this._loadResourcesAsync}
onError={this._handleLoadingError}
onFinish={this._handleFinishLoading}
/>
);
}
return (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ThemeContext.Provider
value={{ theme: this.state.theme, toggleTheme: this.toggleTheme }}
>
<ThemeProvider theme={this.state.theme === 'light' ? light : dark}>
<SafeAreaProvider>
<AppNavigator />
<FlashMessage position="bottom" floating />
</SafeAreaProvider>
</ThemeProvider>
</ThemeContext.Provider>
</ErrorBoundary>
);
}
}