|
| 1 | +import * as Sentry from "@sentry/react-native"; |
1 | 2 | import { Component, type ReactNode } from "react"; |
2 | 3 | import { Pressable, StyleSheet, Text, View } from "react-native"; |
3 | | -import * as Sentry from "@sentry/react-native"; |
| 4 | +import type { AppThemeColors } from "../theme/colors"; |
4 | 5 |
|
5 | 6 | type Props = { |
6 | 7 | children: ReactNode; |
| 8 | + colors?: AppThemeColors; |
7 | 9 | }; |
8 | 10 |
|
9 | 11 | type State = { |
@@ -33,6 +35,7 @@ export default class ErrorBoundary extends Component<Props, State> { |
33 | 35 |
|
34 | 36 | render() { |
35 | 37 | if (this.state.hasError) { |
| 38 | + const styles = createStyles(this.props.colors ?? FALLBACK_ERROR_BOUNDARY_COLORS); |
36 | 39 | return ( |
37 | 40 | <View style={styles.container}> |
38 | 41 | <View style={styles.card}> |
@@ -63,65 +66,89 @@ export default class ErrorBoundary extends Component<Props, State> { |
63 | 66 | } |
64 | 67 | } |
65 | 68 |
|
66 | | -const styles = StyleSheet.create({ |
67 | | - container: { |
68 | | - flex: 1, |
69 | | - backgroundColor: "#0b0b0b", |
70 | | - alignItems: "center", |
71 | | - justifyContent: "center", |
72 | | - paddingHorizontal: 24, |
73 | | - }, |
74 | | - card: { |
75 | | - width: "100%", |
76 | | - borderRadius: 14, |
77 | | - backgroundColor: "#141414", |
78 | | - borderWidth: 1, |
79 | | - borderColor: "#2b2b2b", |
80 | | - paddingVertical: 32, |
81 | | - paddingHorizontal: 20, |
82 | | - alignItems: "center", |
83 | | - gap: 12, |
84 | | - }, |
85 | | - emoji: { |
86 | | - fontSize: 36, |
87 | | - }, |
88 | | - title: { |
89 | | - color: "white", |
90 | | - fontSize: 20, |
91 | | - fontWeight: "800", |
92 | | - textAlign: "center", |
93 | | - }, |
94 | | - message: { |
95 | | - color: "#b7b7b7", |
96 | | - fontSize: 14, |
97 | | - lineHeight: 20, |
98 | | - textAlign: "center", |
99 | | - }, |
100 | | - debugBox: { |
101 | | - width: "100%", |
102 | | - borderRadius: 8, |
103 | | - backgroundColor: "#1a1a1a", |
104 | | - borderWidth: 1, |
105 | | - borderColor: "#333", |
106 | | - paddingVertical: 8, |
107 | | - paddingHorizontal: 10, |
108 | | - }, |
109 | | - debugText: { |
110 | | - color: "#ff6b6b", |
111 | | - fontSize: 12, |
112 | | - fontFamily: "monospace", |
113 | | - }, |
114 | | - button: { |
115 | | - marginTop: 4, |
116 | | - paddingVertical: 12, |
117 | | - paddingHorizontal: 32, |
118 | | - borderRadius: 12, |
119 | | - backgroundColor: "#2c3cff", |
120 | | - alignItems: "center", |
121 | | - }, |
122 | | - buttonText: { |
123 | | - color: "white", |
124 | | - fontWeight: "800", |
125 | | - fontSize: 15, |
126 | | - }, |
127 | | -}); |
| 69 | +const FALLBACK_ERROR_BOUNDARY_COLORS: AppThemeColors = { |
| 70 | + background: "#0b0b0b", |
| 71 | + surface: "#121212", |
| 72 | + surfaceMuted: "#171717", |
| 73 | + surfaceElevated: "#1b1b1b", |
| 74 | + border: "#2b2b2b", |
| 75 | + borderStrong: "#3a3a3a", |
| 76 | + textPrimary: "#ffffff", |
| 77 | + textSecondary: "#d5d5d5", |
| 78 | + textMuted: "#a8a8a8", |
| 79 | + primary: "#2c3cff", |
| 80 | + primaryMuted: "#1a2056", |
| 81 | + primaryText: "#ffffff", |
| 82 | + inputBackground: "#1b1b1b", |
| 83 | + inputBorder: "#2f2f2f", |
| 84 | + inputPlaceholder: "#6f6f6f", |
| 85 | + dangerBackground: "#351515", |
| 86 | + dangerBorder: "#7b2d2d", |
| 87 | + dangerText: "#ffb8b8", |
| 88 | + overlay: "rgba(0,0,0,0.58)", |
| 89 | +}; |
| 90 | + |
| 91 | +function createStyles(colors: AppThemeColors) { |
| 92 | + return StyleSheet.create({ |
| 93 | + container: { |
| 94 | + flex: 1, |
| 95 | + backgroundColor: colors.background, |
| 96 | + alignItems: "center", |
| 97 | + justifyContent: "center", |
| 98 | + paddingHorizontal: 24, |
| 99 | + }, |
| 100 | + card: { |
| 101 | + width: "100%", |
| 102 | + borderRadius: 14, |
| 103 | + backgroundColor: colors.surface, |
| 104 | + borderWidth: 1, |
| 105 | + borderColor: colors.border, |
| 106 | + paddingVertical: 32, |
| 107 | + paddingHorizontal: 20, |
| 108 | + alignItems: "center", |
| 109 | + gap: 12, |
| 110 | + }, |
| 111 | + emoji: { |
| 112 | + fontSize: 36, |
| 113 | + }, |
| 114 | + title: { |
| 115 | + color: colors.textPrimary, |
| 116 | + fontSize: 20, |
| 117 | + fontWeight: "800", |
| 118 | + textAlign: "center", |
| 119 | + }, |
| 120 | + message: { |
| 121 | + color: colors.textMuted, |
| 122 | + fontSize: 14, |
| 123 | + lineHeight: 20, |
| 124 | + textAlign: "center", |
| 125 | + }, |
| 126 | + debugBox: { |
| 127 | + width: "100%", |
| 128 | + borderRadius: 8, |
| 129 | + backgroundColor: colors.inputBackground, |
| 130 | + borderWidth: 1, |
| 131 | + borderColor: colors.inputBorder, |
| 132 | + paddingVertical: 8, |
| 133 | + paddingHorizontal: 10, |
| 134 | + }, |
| 135 | + debugText: { |
| 136 | + color: colors.dangerText, |
| 137 | + fontSize: 12, |
| 138 | + fontFamily: "monospace", |
| 139 | + }, |
| 140 | + button: { |
| 141 | + marginTop: 4, |
| 142 | + paddingVertical: 12, |
| 143 | + paddingHorizontal: 32, |
| 144 | + borderRadius: 12, |
| 145 | + backgroundColor: colors.primary, |
| 146 | + alignItems: "center", |
| 147 | + }, |
| 148 | + buttonText: { |
| 149 | + color: colors.primaryText, |
| 150 | + fontWeight: "800", |
| 151 | + fontSize: 15, |
| 152 | + }, |
| 153 | + }); |
| 154 | +} |
0 commit comments