-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.js
122 lines (104 loc) · 3.33 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import 'react-native-gesture-handler';
import React, {useEffect, useRef, useState} from 'react';
import {AppState, Platform} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {setCustomText} from 'react-native-global-props';
import Tts from 'react-native-tts';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
import {RootStackNavigator} from './src/navigations/RootStackNavigator';
import {LogBox} from 'react-native';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import SplashScreen from 'react-native-splash-screen';
LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message
LogBox.ignoreAllLogs(); //Ignore all log notifications
import {gray900} from './src/themes/colors';
const customTextProps = {
style: {
fontFamily: 'Pretendard-Regular',
color: gray900,
},
};
const queryClient = new QueryClient();
const App = () => {
const appState = useRef(AppState.currentState);
const [appStateVisible, setAppStateVisible] = useState(appState.current);
const [runningTime, setRunningTime] = useState(0);
const [token, setToken] = useState('');
const getToken = async () => {
const token = await AsyncStorage.getItem('accessToken');
setToken(token);
};
const postTime = async token => {
try {
const {data} = await axios.post(
'http://43.201.76.241:8080/api/command/time/register',
{
useTime: '60',
count: '0',
},
{
headers: {
accessToken: token,
},
},
);
console.log('succcess');
console.log(data);
setRunningTime(0);
} catch (err) {}
};
useEffect(() => {
getToken();
try {
SplashScreen.hide();
} catch (e) {
console.warn('스플래시 스크린 닫는데 에러발생');
console.warn(e);
}
setCustomText(customTextProps);
const subscription = AppState.addEventListener('change', nextAppState => {
// if (nextAppState == 'inactive' || nextAppState == 'background') {
// console.log(runningTime);
// //postTime();
// }
appState.current = nextAppState;
setAppStateVisible(appState.current);
});
Tts.getInitStatus().then(
() => {},
err => {
if (err.code === 'no_engine') {
console.log('here');
Tts.requestInstallEngine();
}
},
);
Tts.setDefaultLanguage('ko-KR');
Tts.setIgnoreSilentSwitch('ignore');
Platform.OS == 'android' && Tts.setDefaultRate(0.4);
const interval = setInterval(() => {
appStateVisible == 'active' && setRunningTime(runningTime => runningTime + 1);
}, 1000);
const interval2 = setInterval(async () => {
const token = await AsyncStorage.getItem('accessToken');
postTime(token);
}, 60000);
return () => {
clearInterval(interval);
clearInterval(interval2);
subscription.remove();
};
}, []);
return (
<QueryClientProvider client={queryClient}>
<SafeAreaProvider style={{flex: 1, backgroundColor: 'white'}}>
<NavigationContainer>
<RootStackNavigator />
</NavigationContainer>
</SafeAreaProvider>
</QueryClientProvider>
);
};
export default App;