Bluesky app fork with some witchin' additions 馃挮
at readme-update 64 lines 1.5 kB view raw
1import {Component, type ErrorInfo, type ReactNode} from 'react' 2import {type StyleProp, type ViewStyle} from 'react-native' 3import {msg} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {logger} from '#/logger' 7import {ErrorScreen} from './error/ErrorScreen' 8import {CenteredView} from './Views' 9 10interface Props { 11 children?: ReactNode 12 renderError?: (error: any) => ReactNode 13 style?: StyleProp<ViewStyle> 14} 15 16interface State { 17 hasError: boolean 18 error: any 19} 20 21export class ErrorBoundary extends Component<Props, State> { 22 public state: State = { 23 hasError: false, 24 error: undefined, 25 } 26 27 public static getDerivedStateFromError(error: Error): State { 28 return {hasError: true, error} 29 } 30 31 public componentDidCatch(error: Error, errorInfo: ErrorInfo) { 32 logger.error(error, {errorInfo}) 33 } 34 35 public render() { 36 if (this.state.hasError) { 37 if (this.props.renderError) { 38 return this.props.renderError(this.state.error) 39 } 40 41 return ( 42 <CenteredView style={[{height: '100%', flex: 1}, this.props.style]}> 43 <TranslatedErrorScreen details={this.state.error.toString()} /> 44 </CenteredView> 45 ) 46 } 47 48 return this.props.children 49 } 50} 51 52function TranslatedErrorScreen({details}: {details?: string}) { 53 const {_} = useLingui() 54 55 return ( 56 <ErrorScreen 57 title={_(msg`Oh no!`)} 58 message={_( 59 msg`There was an unexpected issue in the application. Please let us know if this happened to you!`, 60 )} 61 details={details} 62 /> 63 ) 64}