-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
82 lines (75 loc) · 2.34 KB
/
App.js
File metadata and controls
82 lines (75 loc) · 2.34 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
import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { View, Text, StyleSheet } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { HomeScreen } from './src/screens/HomeScreen';
import { NoteDetailScreen } from './src/screens/NoteDetailScreen';
import { AddNoteScreen } from './src/screens/AddNoteScreen';
import { theme } from './src/theme';
const Stack = createStackNavigator();
// Error Boundary Component
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, errorInfo) {
console.error('App Error:', error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
<View style={styles.errorContainer}>
<Text style={styles.errorTitle}>Something went wrong</Text>
<Text style={styles.errorMessage}>{this.state.error?.message || 'Unknown error'}</Text>
</View>
);
}
return this.props.children;
}
}
export default function App() {
return (
<ErrorBoundary>
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<StatusBar style="dark" />
<Stack.Navigator
screenOptions={{
headerShown: false,
cardStyle: { backgroundColor: theme.colors.background },
}}
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="NoteDetail" component={NoteDetailScreen} />
<Stack.Screen name="AddNote" component={AddNoteScreen} />
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
</ErrorBoundary>
);
}
const styles = StyleSheet.create({
errorContainer: {
flex: 1,
backgroundColor: theme.colors.background,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
errorTitle: {
...theme.typography.heading,
color: theme.colors.error,
marginBottom: 10,
},
errorMessage: {
...theme.typography.body,
color: theme.colors.text,
textAlign: 'center',
},
});