-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
58 lines (50 loc) · 1.55 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
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import StackNav from './src/navigation/StackNav';
import { createContext, useEffect, useState } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { btoa, atob } from 'react-native-quick-base64';
export const TriviaContext = createContext();
export default function App() {
const [appTheme,setAppTheme] = useState('#FF5733');
const [openFirstTime,setOpenFirstTime] = useState('false');
const [gameLevel,setGameLevel] = useState('');
const [quizType,setQuizType] = useState('');
const [categoryType,setCategoryType] = useState('');
const [autoQuiz,setAutoQuiz] = useState();
const getData = async () => {
try {
const value = await AsyncStorage.getItem('welcome-status');
if (value !== null) {
// value previously stored
setOpenFirstTime(value);
}
} catch (e) {
// error reading value
}
};
const decodeBase64 = (base64String) => {
try {
const decodedString = atob(base64String);
return decodedString;
} catch (error) {
console.error('Error decoding base64: ', error);
return null;
}
};
useEffect(()=>{
getData();
},[])
return (
<TriviaContext.Provider value={{appTheme,
setAppTheme,decodeBase64,
openFirstTime,setOpenFirstTime,
gameLevel,setGameLevel,
quizType,setQuizType,
categoryType,setCategoryType,
autoQuiz,setAutoQuiz
}}>
<StackNav />
</TriviaContext.Provider>
);
}