import React, { Component, ErrorInfo, ReactNode } from 'react'; import { View, Text, StyleSheet, TouchableOpacity, SafeAreaView } from 'react-native'; import { Feather } from '@expo/vector-icons'; interface Props { children: ReactNode; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends Component { public state: State = { hasError: false, error: null, }; public static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo); // Technical fix: Report error to backend logs const { ApiService } = require('../services/api'); ApiService.reportError(error.message, 'critical', { componentStack: errorInfo.componentStack, platform: require('react-native').Platform.OS, }); } private handleReset = () => { this.setState({ hasError: false, error: null }); }; public render() { if (this.state.hasError) { return ( Oops! Something went wrong An unexpected error occurred. Don't worry, your data is safe. {__DEV__ && ( {this.state.error?.toString()} )} Try Again ); } return this.props.children; } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#FFFFFF' }, content: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 40 }, iconBox: { width: 120, height: 120, borderRadius: 40, backgroundColor: '#FFF0F0', alignItems: 'center', justifyContent: 'center', marginBottom: 30 }, title: { fontSize: 24, fontFamily: 'Outfit_800ExtraBold', color: '#1A1A1A', textAlign: 'center', marginBottom: 12 }, desc: { fontSize: 15, fontFamily: 'Outfit_400Regular', color: '#666', textAlign: 'center', lineHeight: 22, marginBottom: 40 }, errorBox: { width: '100%', padding: 16, backgroundColor: '#F5F5F5', borderRadius: 12, marginBottom: 30 }, errorText: { fontSize: 12, fontFamily: 'Monaco', color: '#888' }, btn: { width: '100%', height: 56, borderRadius: 16, backgroundColor: '#1A1A1A', alignItems: 'center', justifyContent: 'center' }, btnText: { color: '#FFFFFF', fontSize: 16, fontFamily: 'Outfit_700Bold' }, });