-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
77 lines (69 loc) · 2.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, {useState, useEffect} from 'react';
import AppNavigator from './src/AppNavigator';
import {View, Text, ScrollView} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Introduction2 from './src/App_Page/InitialPage/Introduction2';
import ThemeProvider from './src/Theme/ThemeContext';
import IntroNavigator from "./src/App_Page/InitialPage/IntroNavigator"
import {
SafeAreaProvider,
initialWindowMetrics,
} from 'react-native-safe-area-context';
import { useFirstTimeUseApp } from './src/Zustand/FirstTimeUseApp';
interface UserInfoProps {
firstTimeUseApp: boolean;
}
export default function App() {
const [data, setData] = useState<any>();
// const [isFirstTimeUseApp, setIsFirstTimeUseApp] = useState<boolean>(true);
const firstTimeUseApp = useFirstTimeUseApp((state) => state.firstTimeUseApp);
const setFirstTimeUseApp = useFirstTimeUseApp((state) => state.setFirstTimeUseApp);
useEffect(() => {
async function GetData() {
const getIsFirstTimeUseApp = await GetInitialPageStatus()
.then((value: any) => {
console.log('value', value);
return value;
})
.catch(err => {
console.log('Error in Get', err);
});
setFirstTimeUseApp(getIsFirstTimeUseApp);
}
GetData();
}, []);
const defaultStatus = null;
return (
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<ThemeProvider>
{defaultStatus === true ? <IntroNavigator /> : <AppNavigator />}
</ThemeProvider>
</SafeAreaProvider>
);
}
// Function get Item key in local device
const GetInitialPageStatus = async () => {
try {
// Retrieve the JSON string from AsyncStorage
const jsonData = await AsyncStorage.getItem('firstTimeUseApp');
if (jsonData !== null) {
// Parse the JSON string back to an array or object
const parsedData: UserInfoProps = JSON.parse(jsonData);
const firstTimeUseApp = parsedData.firstTimeUseApp;
console.log('firstTimeUseApp', firstTimeUseApp);
return firstTimeUseApp;
} else {
// Handle the case where the key is not yet stored
console.log('No data found in AsyncStorage. Initializing with default data.',);
// Example: Set some default data if the key is not found
// const storeData: UserInfoProps = {firstTimeUseApp: true};
// await AsyncStorage.setItem('firstTimeUseApp', JSON.stringify(storeData));
// console.log('Default data set in AsyncStorage');
// return true;
return true;
}
} catch (error) {
console.error('Error loading data:', error);
}
};