-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileScreen.js
100 lines (73 loc) · 3.14 KB
/
ProfileScreen.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
import React, { useState, useEffect, useCallback} from 'react';
import {StatusBar, SectionList, Dimensions, SafeAreaView, Image, StyleSheet, View, TouchableOpacity, Text, Animated, Platform } from 'react-native';
import { PanGestureHandler, State, GestureHandlerRootView } from 'react-native-gesture-handler';
import { runOnJS } from 'react-native-reanimated';
import styles from './styles';
import {auth, firestore} from './firebase';
import {useNavigation} from '@react-navigation/core';
import { useFocusEffect } from '@react-navigation/native';
import { doc, getDoc, updateDoc, setDoc } from "firebase/firestore";
import tinycolor from 'tinycolor2';
import Dot from './assets/dot.svg';
import Flash from './assets/flash.svg';
import Logo from './assets/newLogo.svg';
import SvgUri from 'react-native-svg'
import {deviceWidth, deviceHeight} from './styles';
import Profile from './assets/profile.svg';
import NetInfo from "@react-native-community/netinfo";
StatusBar.setTranslucent(true);
StatusBar.setBackgroundColor('white'); // Set this to match your app's background color if necessary
const ProfileScreen = () => {
const statusBarHeight = Platform.OS === 'android' ? StatusBar.currentHeight : 0;
const navigation = useNavigation();
const backHome = () => {
navigation.navigate('MainScreen')
}
const handleLogout = () => {
auth
.signOut()
.then(() => {
navigation.navigate("LoginScreen")
})
.catch((error) => {
alert(error.message);
console.error(error);
});
}
useEffect(() => {
const unsubscribe = NetInfo.addEventListener(state => {
if (!state.isConnected) {
// User has lost internet connection
// Log out the user and redirect to login screen
// (You may also want to save the current state before logging out)
auth.signOut().then(() => {
navigation.navigate('LoginScreen');
}).catch(error => {
console.error("Logout error", error);
alert("Your internet connection has been lost. Please log in again.");
});
}
});
return () => {
unsubscribe();
};
}, []);
return (
<SafeAreaView style={[styles.container, { marginTop: statusBarHeight }]}>
<View style={styles.loginContainer2}>
<TouchableOpacity onPress={backHome} style={styles.backToMain}>
<Text style={{ textAlign: 'left', fontSize: 20, padding: 10, paddingTop: 5 }}>
<Image source={require('./assets/arrow_left.png')} style={styles.iconStyle3} />
Back to MainScreen
</Text>
</TouchableOpacity>
<Text style={{fontSize:deviceHeight*0.03,marginTop: 100,}}>Email:</Text>
<Text style={{fontSize:deviceHeight*0.02}}> {auth.currentUser?.email}</Text>
<TouchableOpacity onPress={handleLogout} style={{marginTop: 100, backgroundColor:'lightgrey', borderWidth: 1,
borderColor: 'black', borderRadius: 20, minWidth: deviceWidth*0.2, minHeight: deviceHeight*0.04
, justifyContent: 'center', alignItems: 'center'}}><Text>Log Out</Text></TouchableOpacity>
</View>
</SafeAreaView>
);
}
export default ProfileScreen;