-
Notifications
You must be signed in to change notification settings - Fork 37
/
App.js
52 lines (48 loc) · 1.18 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
import React, { Component } from 'react';
import { BackHandler, NetInfo, Alert } from 'react-native';
import { Provider } from 'mobx-react/native';
import stores from './src/store';
import App from './src';
// const NimApp = () => (
// <Provider {...stores}>
// <App />
// </Provider>
// );
const handleConnectivityChange = () => {
NetInfo.isConnected.fetch().then((isConnected) => {
if (!isConnected) {
Alert.alert('提示', '网络已断开,请连接网络重试');
}
});
};
export default class NimApp extends Component {
constructor(props) {
super(props);
BackHandler.addEventListener(
'hardwareBackPress',
this.onBackButtonPressAndroid,
);
NetInfo.isConnected.addEventListener(
'connectionChange',
handleConnectivityChange,
);
}
componentWillUnmount() {
BackHandler.removeEventListener(
'hardwareBackPress',
this.onBackButtonPressAndroid,
);
NetInfo.isConnected.removeEventListener(
'connectionChange',
handleConnectivityChange,
);
}
onBackButtonPressAndroid = () => true
render() {
return (
<Provider {...stores}>
<App />
</Provider>
);
}
}