-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
44 lines (39 loc) · 1.07 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
import React, {PureComponent} from 'react';
import {BackHandler, ToastAndroid, StatusBar} from 'react-native';
import SplashScreen from 'react-native-splash-screen';
import './src/utils/globa';
import Index from './src';
class App extends PureComponent {
componentWillMount() {
if (Platform.OS === 'android') {
BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
}
}
componentWillUnmount() {
if (Platform.OS === 'android') {
BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
}
}
async componentDidMount() {
setTimeout(() => {
SplashScreen.hide();
}, 500);
}
onBackAndroid = () => {
if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
//最近2秒内按过back键,可以退出应用。
return false;
}
this.lastBackPressed = Date.now();
ToastAndroid && ToastAndroid.show('再按一次就退出!', ToastAndroid.SHORT);
return true;
};
render() {
return (
<>
<Index />
</>
);
}
}
export default App;