-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
98 lines (77 loc) · 2.7 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, BackHandler, NetInfo, } from 'react-native';
import Navigator from './src/navigation';
import { Toast } from 'teaset';
import { Provider } from 'mobx-react';
import rootStore from './src/mobx/index';
import NavigationService from './src/commons/components/navigationService';
import * as Sentry from '@sentry/react-native';
export default class App extends Component {
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._onBackAndroid);
NetInfo.addEventListener('connectionChange', this.handleFirstConnectivityChange);
Sentry.init({
dsn: 'https://[email protected]/5379271',
});
// Sentry.setTag("myTag", "tag-value");
// Sentry.setExtra("myExtra", "extra-value");
// Sentry.addBreadcrumb({ message: "test" });
Sentry.captureMessage("wwwwwwn你好!");
}
componentUnWillMount() {
BackHandler.removeEventListener('hardwareBackPress', this._onBackAndroid);
NetInfo.removeEventListener('connectionChange', this.handleFirstConnectivityChange);
}
_onBackAndroid = () => {
if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
//最近2秒内按过back键,可以退出应用。
BackHandler.exitApp();
}
this.lastBackPressed = Date.now();
Toast.message('再按一次退出应用');
return true;
}
handleFirstConnectivityChange = (connectionInfo) => {
let that = this;
console.log('网络事件监听, type: ' + connectionInfo.type + ', effectiveType: ' + connectionInfo.effectiveType);
if (connectionInfo.type == 'none') {
//没有网络
Toast.message('网络已断开,请检查网络连接!')
} else {
//有网络
if (connectionInfo.type == 'wifi') {
Toast.message('当前网络状态为:' + connectionInfo.type)
} else {
//其他网络状态
}
}
}
_getRef(ref) {
NavigationService.setNavigator(ref);
}
render() {
return (
<Provider rootStore={rootStore}>
<Navigator
ref={(ref) => this._getRef(ref)}
onNavigationStateChange={(prevState, newState, action) => {
// console.log(newState);
if (newState.routes[1].routes.length > 1) {
BackHandler.removeEventListener('hardwareBackPress', this._onBackAndroid);
} else {
BackHandler.addEventListener('hardwareBackPress', this._onBackAndroid);
}
}}
/>
</Provider>
);
}
}