-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
77 lines (66 loc) · 2.2 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
import React, { useEffect } from "react";
import { Alert, LogBox } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import Start from "./components/Start";
import Chat from "./components/Chat";
import { initializeApp } from "firebase/app";
import { getFirestore, disableNetwork, enableNetwork } from "firebase/firestore";
import { useNetInfo } from "@react-native-community/netinfo";
import { getStorage } from "firebase/storage";
LogBox.ignoreLogs(["AsyncStorage has been extracted from"]);
const Stack = createNativeStackNavigator();
const App = () => {
const connectionStatus = useNetInfo();
const firebaseConfig = {
apiKey: "AIzaSyB2ho8ZxntFih_WLFKCbWcLh8hXhQba9zQ",
authDomain: "zen-zapp.firebaseapp.com",
projectId: "zen-zapp",
storageBucket: "zen-zapp.appspot.com",
messagingSenderId: "189202496542",
appId: "1:189202496542:web:7430e03b93811f9245820f",
measurementId: "G-XFNCCEQ8LM"
}
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Cloud Firestore and get a reference to the service
const db = getFirestore(app);
const storage = getStorage(app);
useEffect(() => {
if (connectionStatus.isConnected === false) {
Alert.alert("No connection");
disableNetwork(db);
} else if (connectionStatus.isConnected === true) {
enableNetwork(db);
}
}, [connectionStatus.isConnected]);
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Start">
<Stack.Screen
name="Start"
component={Start}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Chat"
options={({ route }) => ({
title: route.params?.userName ?? "Chat",
headerStyle: {
backgroundColor: route.params?.backgroundColor ?? "#757083",
},
headerTintColor: "#FFFFFF",
headerTitleStyle: { fontWeight: "bold" },
})}
>
{(props) => <Chat
isConnected={connectionStatus.isConnected}
db={db}
storage={storage}
{...props} />}
</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;