-
Notifications
You must be signed in to change notification settings - Fork 7
/
App.js
131 lines (114 loc) · 3.91 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
123
124
125
126
127
128
129
130
131
import React, { useState,useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import HomeScreen from './app/screens/HomeScreen';
import HadithsScreen from './app/screens/HadithsScreen';
import SettingsScreen from './app/screens/SettingsScreen';
import { Platform,Alert,StatusBar } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { SSContexts } from './contexts/SSContexts';
import { Feather } from '@expo/vector-icons';
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const HomeTabs = () => {
return (
<Tab.Navigator screenOptions={{ headerShown: false,tabBarActiveTintColor: '#6a3eb2'}}
>
<Tab.Screen
name="Tab1"
component={HomeScreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color, size }) => (
<Feather name="home" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="settings"
component={SettingsScreen}
options={{
tabBarLabel: 'Settings',
tabBarIcon: ({ color, size }) => (
<Feather name="settings" color={color} size={size} />
),
}}
/>
</Tab.Navigator>
);
};
export default function App() {
const [hadithBook, setHadithBook] = useState("bukhari");
const [hadithLang, setHadithLang] = useState("eng");
const [internet, setInternet] = useState(true);
useEffect(() => {
// Check if the book has been set before
AsyncStorage.getItem('book')
.then((book) => {
if (book != null) {
// If book exists, set it to hadithBook variable
setHadithBook(book);
}else{
AsyncStorage.setItem('book', 'bukhari');
setHadithBook('bukhari');
}
})
.catch((error) => console.error('Error reading book:', error));
}, []);
useEffect(() => {
// Check if the book has been set before
AsyncStorage.getItem('lang')
.then((lang) => {
if (lang !== null) {
// If book exists, set it to hadithBook variable
setHadithLang(lang);
}else{
AsyncStorage.setItem('lang', 'eng');
setHadithLang('eng');
}
})
.catch((error) => console.error('Error reading lang:', error));
}, []);
async function checkInternetConnection() {
try {
const response = await fetch('https://www.google.com', { mode: 'no-cors' });
if (response.status >= 200 && response.status < 300) {
// Internet connection is available
return true;
} else {
// Internet connection is not available
return false;
}
} catch (error) {
// Fetch failed, internet connection is not available
return false;
}
}
// Example usage:
useEffect(() => {
checkInternetConnection().then(hasInternet => {
if (hasInternet) {
setInternet(true)
} else {
setInternet(false)
Alert.alert("No Internet","Please check your internet connection")
}
}) });
return (
<SSContexts.Provider value={{hadithBook,setHadithBook,hadithLang,setHadithLang}}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerStyle: {
marginTop: (Platform.OS === 'ios') ? 0 : StatusBar.currentHeight
},
}}>
<Stack.Screen name="Home" component={HomeTabs} options={{headerShown:false}}/>
<Stack.Screen name="Hadiths" component={HadithsScreen} options={{headerShown:false}}/>
<Stack.Screen name="Settings" component={SettingsScreen} options={{headerShown:false}}/>
</Stack.Navigator>
</NavigationContainer>
</SSContexts.Provider>
);
}