-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
53 lines (45 loc) · 1.64 KB
/
App.tsx
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
import { ThemeProvider } from './ThemeContext'
import React, { useState, useEffect } from "react"
import AsyncStorage from "@react-native-async-storage/async-storage"
import PasswordPrompt from "./components/PasswordPrompt"
import AppNavigator from "./navigation/AppNavigator"
import { ActivityIndicator, View } from "react-native"
import "./i18n"
import { useTranslation } from "react-i18next"
const App: React.FC = () => {
const { t, i18n } = useTranslation();
const [authenticated, setAuthenticated] = useState<boolean>(false);
const [isPasswordSet, setIsPasswordSet] = useState<boolean | null>(null);
const [isLanguageLoaded, setIsLanguageLoaded] = useState<boolean>(false);
useEffect(() => {
const checkStoredPassword = async () => {
const password = await AsyncStorage.getItem("app_password");
setIsPasswordSet(!!password);
};
const loadLanguage = async () => {
const savedLanguage = await AsyncStorage.getItem("language");
console.log(savedLanguage)
if (savedLanguage) {
await i18n.changeLanguage(savedLanguage);
}
setIsLanguageLoaded(true);
};
checkStoredPassword();
loadLanguage();
}, []);
// Show loading indicator while checking AsyncStorage
if (isPasswordSet === null || !isLanguageLoaded) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator size="large" />
</View>
);
}
if (isPasswordSet && !authenticated) {
return <PasswordPrompt onAuthenticate={setAuthenticated} />;
}
return <ThemeProvider>
<AppNavigator />
</ThemeProvider>;
};
export default App;