-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
100 lines (84 loc) · 3.28 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
import { NativeRouter, Route } from 'react-router-native';
import { Notifications, SecureStore } from 'expo';
import { StyleSheet, View, AppRegistry, NetInfo } from 'react-native';
import React from 'react';
import Sentry from 'sentry-expo';
import { name as appName } from './app.json';
import Error from './src/components/Error';
import Game from './src/components/Game';
import Home from './src/components/Home';
import Invite from './src/components/Invite';
import Login from './src/components/Login';
import Offline from './src/components/Offline';
import Profile from './src/components/Profile';
import Ranglist from './src/components/Ranglist';
import Register from './src/components/Register';
import Settings from './src/components/Settings';
import Splash from './src/components/Splash';
Sentry.enableInExpoDevelopment = false;
Sentry.config('https://[email protected]/1434373').install();
export default class App extends React.Component {
state = {
isConnected: true,
hasError: false,
notification: null
}
componentDidMount () {
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange)
Notifications.createChannelAndroidAsync('game_invite', {
name: 'Покани за игра',
sound: true,
priority: 'max'
});
this._notificationSubscription = Notifications.addListener(this.handleNotification)
}
componentDidCatch(error, info) {
Sentry.captureException(error, info);
this.setState({ hasError: true});
}
handleNotification = (notification) => {
if (notification.origin === 'selected') {
this.setState({ notification })
}
};
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange);
}
handleConnectivityChange = isConnected => this.setState({ isConnected });
render () {
const { isConnected, hasError, notification } = this.state;
return (
<NativeRouter>
<View style={styles.container}>
<Route exact path='/' component={Splash} />
<Route path='/login' component={Login} />
<Route path='/register' component={Register} />
<Route path='/home' component={Home} />
<Route path='/game/:uuid/' component={Game} />
<Route path='/ranglist' component={Ranglist}/>
<Route path='/profile/:id/' component={Profile}/>
<Route path='/settings' component={Settings}/>
{
!isConnected &&
<Offline/>
}
{
hasError &&
<Error/>
}
{
notification && notification.origin === 'selected' &&
<Invite notification={notification} parent={this}/>
}
</View>
</NativeRouter>
);
}
}
AppRegistry.registerComponent(appName, () => App);
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%'
}
});