Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
107 lines (95 loc) · 2.88 KB
/
Copy pathApp.js
File metadata and controls
107 lines (95 loc) · 2.88 KB
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
// App.js
// FINAL - Fixed navigation and white screen
import React, { useState, useEffect, useRef } from 'react';
import { View, Text, ActivityIndicator, StyleSheet, StatusBar } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { onAuthStateChanged } from 'firebase/auth';
import { auth } from './firebaseConfig';
import AppNavigator from './navigation/AppNavigator';
export default function App() {
const [isReady, setIsReady] = useState(false);
const [initialRouteName, setInitialRouteName] = useState('Login');
const initialAuthResolved = useRef(false);
useEffect(() => {
let cancelled = false;
const unsubscribe = onAuthStateChanged(auth, async (user) => {
if (cancelled) return;
try {
if (user) {
await AsyncStorage.setItem('userId', user.uid);
await AsyncStorage.setItem('userEmail', user.email || '');
} else {
await AsyncStorage.removeItem('userId');
await AsyncStorage.removeItem('userEmail');
await AsyncStorage.removeItem('currentUser');
}
} catch (e) {
console.error('Auth storage sync error:', e);
}
if (cancelled) return;
if (!initialAuthResolved.current) {
initialAuthResolved.current = true;
setInitialRouteName(user ? 'Home' : 'Login');
setIsReady(true);
}
});
return () => {
cancelled = true;
unsubscribe();
};
}, []);
if (!isReady) {
return (
<View style={styles.loadingContainer}>
<StatusBar backgroundColor="#FFFFFF" barStyle="dark-content" />
<Text style={styles.logo}>🚨</Text>
<Text style={styles.appName}>Zero Trap</Text>
<Text style={styles.tagline}>Emergency Help Network</Text>
<ActivityIndicator size="large" color="#FF3B30" style={styles.loader} />
<Text style={styles.loadingText}>Starting app...</Text>
</View>
);
}
console.log('📱 Rendering app with initial route:', initialRouteName);
return (
<SafeAreaProvider>
<NavigationContainer>
<StatusBar backgroundColor="#FF3B30" barStyle="light-content" />
<AppNavigator initialRoute={initialRouteName} />
</NavigationContainer>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
loadingContainer: {
flex: 1,
backgroundColor: '#FFFFFF',
justifyContent: 'center',
alignItems: 'center',
},
logo: {
fontSize: 100,
marginBottom: 20,
},
appName: {
fontSize: 36,
fontWeight: 'bold',
color: '#FF3B30',
marginBottom: 10,
},
tagline: {
fontSize: 16,
color: '#666',
marginBottom: 40,
},
loader: {
marginTop: 20,
},
loadingText: {
fontSize: 14,
color: '#999',
marginTop: 15,
},
});