-
Notifications
You must be signed in to change notification settings - Fork 968
Expand file tree
/
Copy pathErrorGeneratorScreen.tsx
More file actions
93 lines (86 loc) · 2.73 KB
/
ErrorGeneratorScreen.tsx
File metadata and controls
93 lines (86 loc) · 2.73 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
import React from "react"
import { ScrollView, TextStyle, View, ViewStyle } from "react-native"
import { useDispatch } from "react-redux"
import { Button, Text } from "app/components"
import type { AppStackScreenProps } from "app/navigators"
import { colors, spacing } from "app/theme"
import type { AppDispatch } from "app/stores/redux"
import { throwAnError, throwErrorAsync } from "app/stores/redux/errorSlice"
import { useSafeAreaInsetsStyle } from "app/utils/useSafeAreaInsetsStyle"
interface ErrorGeneratorScreenProps extends AppStackScreenProps<"ErrorGenerator"> {}
export const ErrorGeneratorScreen: React.FC<ErrorGeneratorScreenProps> =
function ErrorGeneratorScreen() {
const dispatch = useDispatch<AppDispatch>()
const bomb = () => {
console.log("wait for it...")
setTimeout(() => {
throw new Error("Boom goes the error message.")
}, 500)
}
const silentBomb = () => {
// you may have try/catch blocks in your code
try {
// ignore this, we want to generate the error
// @ts-ignore
console.foo()
} catch (e) {
// now you can log those errors
console.error(e)
}
}
const bombRedux = () => dispatch(throwAnError())
// @ts-ignore
const bombReduxAsync = () => dispatch(throwErrorAsync())
const $bottomContainerInsets = useSafeAreaInsetsStyle(["bottom"])
return (
<ScrollView style={$container} contentContainerStyle={$bottomContainerInsets}>
<View style={$topContainer}>
<Text style={$text} tx="errorGeneratorScreen.title" />
</View>
<View style={{ marginTop: spacing.lg }}>
<Button
textStyle={$darkText}
tx="errorGeneratorScreen.componentError"
onPress={bomb}
style={$button}
/>
<Button
textStyle={$darkText}
tx="errorGeneratorScreen.tryCatchError"
onPress={silentBomb}
style={$button}
/>
<Button
textStyle={$darkText}
tx="errorGeneratorScreen.reduxError"
onPress={bombRedux}
style={$button}
/>
<Button
textStyle={$darkText}
tx="errorGeneratorScreen.reduxAsyncError"
onPress={bombReduxAsync}
style={$button}
/>
</View>
</ScrollView>
)
}
const $container: ViewStyle = {
flex: 1,
backgroundColor: colors.background,
}
const $topContainer: ViewStyle = {
paddingHorizontal: spacing.lg,
paddingTop: spacing.xl,
}
const $text: TextStyle = {
color: colors.text,
}
const $darkText: TextStyle = {
color: colors.textDim,
}
const $button: ViewStyle = {
marginHorizontal: spacing.xxxl,
marginVertical: spacing.sm,
}