-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
66 lines (58 loc) · 1.69 KB
/
App.tsx
File metadata and controls
66 lines (58 loc) · 1.69 KB
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
import 'react-native-gesture-handler';
import React, {useEffect, useRef} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {LogBox, ToastAndroid, BackHandler} from 'react-native';
import Storage from 'react-native-storage';
import AsyncStorage from '@react-native-async-storage/async-storage';
LogBox.ignoreLogs(["exported from 'deprecated-react-native-prop-types'."]);
LogBox.ignoreAllLogs(true);
//Setting the storage options
const storage = new Storage({
size: 1000,
storageBackend: AsyncStorage,
defaultExpires: 1000 * 3600 * 24 * 365, // 1 year
enableCache: true,
sync: {},
});
//setting global variables and functions that can be used over the whole app
global.storage = storage;
import MainNavigator from './src/navigation/MainNavigator';
export default function App() {
let clicks = 0;
const routeNameRef = useRef();
const navigationRef = useRef();
const backAction = () => {
if (navigationRef.current.getCurrentRoute().name === 'Home') {
if (clicks > 0) {
BackHandler.exitApp();
} else {
ToastAndroid.show(
'click again to exit Bethere',
ToastAndroid.SHORT,
ToastAndroid.CENTER,
);
clicks++;
}
setTimeout(() => {
clicks = 0;
}, 1000);
return true;
}
return false;
};
useEffect(() => {
const init = async () => {
BackHandler.addEventListener('hardwareBackPress', backAction);
};
init();
}, []);
return (
<NavigationContainer
ref={navigationRef}
onReady={() =>
(routeNameRef.current = navigationRef.current.getCurrentRoute().name)
}>
<MainNavigator />
</NavigationContainer>
);
}