-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathApp.tsx
More file actions
268 lines (248 loc) · 7.65 KB
/
Copy pathApp.tsx
File metadata and controls
268 lines (248 loc) · 7.65 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import Constants from "expo-constants";
import * as Device from "expo-device";
import * as SplashScreen from "expo-splash-screen";
import { StatusBar } from "expo-status-bar";
import { useEffect, useMemo, useState } from "react";
import { Platform, Pressable, StyleSheet, Text, View } from "react-native";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import { Tabs, type TabSelectedEvent } from "react-native-screens";
import { Exceptionless } from "@exceptionless/react-native";
import { callbackLog, getLogEntries, subscribeToLogs } from "./logging";
import ErrorsScreen from "./screens/ErrorsScreen";
import EventsScreen from "./screens/EventsScreen";
import LogsScreen from "./screens/LogsScreen";
type TabKey = "Errors" | "Events" | "Logs";
const appTabs: Array<{ icon: string; key: TabKey; title: string }> = [
{ icon: "exclamationmark.triangle", key: "Errors", title: "Errors" },
{ icon: "tray.and.arrow.up", key: "Events", title: "Events" },
{ icon: "list.bullet.rectangle", key: "Logs", title: "Logs" }
];
const serverUrl = getServerUrl();
/**
* Resolves the dev server URL based on the current platform.
* - Web and iOS Simulator: localhost reaches the host Mac.
* - Android Emulator: 10.0.2.2 reaches the host machine.
* - Real Android devices: need the dev machine's IP, extracted from Expo's hostUri.
*/
function getServerUrl(): string {
if (!__DEV__ || Platform.OS === "web" || Platform.OS === "ios") {
return "http://localhost:7110";
}
if (!Device.isDevice) {
return "http://10.0.2.2:7110";
}
const hostUri = Constants.expoConfig?.hostUri;
if (hostUri) {
try {
const hostname = new URL(`http://${hostUri}`).hostname;
return `http://${hostname}:7110`;
} catch {
// Fall through to default
}
}
return "http://localhost:7110";
}
function TopDiagnostics() {
const [logs, setLogs] = useState(() => getLogEntries());
const latestLog = logs.at(-1);
const errorCount = useMemo(() => logs.filter((entry) => entry.level === "error").length, [logs]);
useEffect(() => subscribeToLogs(() => setLogs(getLogEntries())), []);
return (
<SafeAreaView edges={["top"]} style={styles.diagnosticsSafeArea}>
<View style={styles.diagnostics}>
<View style={styles.diagnosticsTitleRow}>
<Text style={styles.diagnosticsTitle}>Exceptionless Expo</Text>
<Text style={styles.diagnosticsPill}>SDK 56</Text>
</View>
<Text style={styles.diagnosticsServer} numberOfLines={1}>
{serverUrl}
</Text>
<View style={styles.diagnosticsMetaRow}>
<Text style={styles.diagnosticsMeta}>{logs.length} logs</Text>
<Text style={styles.diagnosticsMeta}>{errorCount} errors</Text>
<Text style={styles.diagnosticsMeta}>sessions on</Text>
</View>
<Text style={styles.latestLog} numberOfLines={2}>
{latestLog ? `[${latestLog.level.toUpperCase()}] ${latestLog.message}` : "Waiting for Exceptionless startup logs..."}
</Text>
</View>
</SafeAreaView>
);
}
function NativeTabs() {
const [selectedTab, setSelectedTab] = useState<TabKey>("Errors");
const [baseProvenance, setBaseProvenance] = useState(0);
const navStateRequest = useMemo(() => ({ baseProvenance, selectedScreenKey: selectedTab }), [baseProvenance, selectedTab]);
const handleTabSelected = (event: { nativeEvent: TabSelectedEvent }) => {
setSelectedTab(event.nativeEvent.selectedScreenKey as TabKey);
setBaseProvenance(event.nativeEvent.provenance);
};
if (Platform.OS === "web") {
const ActiveScreen = selectedTab === "Errors" ? ErrorsScreen : selectedTab === "Events" ? EventsScreen : LogsScreen;
return (
<View style={styles.webTabs}>
<View style={styles.webTabContent}>
<ActiveScreen />
</View>
<View style={styles.webTabBar}>
{appTabs.map((tab) => (
<Pressable
key={tab.key}
accessibilityRole="tab"
accessibilityState={{ selected: selectedTab === tab.key }}
onPress={() => setSelectedTab(tab.key)}
style={styles.webTabButton}
>
<Text style={[styles.webTabLabel, selectedTab === tab.key && styles.webTabLabelActive]}>{tab.title}</Text>
</Pressable>
))}
</View>
</View>
);
}
return (
<Tabs.Host
colorScheme="light"
ios={{
tabBarControllerMode: "tabBar",
tabBarMinimizeBehavior: "never",
tabBarTintColor: "#0f172a"
}}
nativeContainerStyle={styles.nativeTabsContainer}
navStateRequest={navStateRequest}
onTabSelected={handleTabSelected}
rejectStaleNavStateUpdates
>
{appTabs.map((tab) => {
const Screen = tab.key === "Errors" ? ErrorsScreen : tab.key === "Events" ? EventsScreen : LogsScreen;
return (
<Tabs.Screen ios={{ icon: { name: tab.icon, type: "sfSymbol" } }} key={tab.key} screenKey={tab.key} style={styles.nativeTabScreen} title={tab.title}>
<Screen />
</Tabs.Screen>
);
})}
</Tabs.Host>
);
}
export default function App() {
useEffect(() => {
void Exceptionless.startup((config) => {
config.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271nTest";
config.serverUrl = serverUrl;
config.services.log = callbackLog;
config.defaultTags.push("Example", "Expo");
config.useSessions(true, 60000, true);
});
void SplashScreen.hideAsync();
}, []);
return (
<SafeAreaProvider>
<View style={styles.appShell}>
<TopDiagnostics />
<NativeTabs />
</View>
<StatusBar style="auto" />
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
appShell: {
flex: 1,
backgroundColor: "#fff"
},
diagnosticsSafeArea: {
backgroundColor: "#fff"
},
diagnostics: {
borderBottomColor: "#e5e7eb",
borderBottomWidth: StyleSheet.hairlineWidth,
paddingBottom: 10,
paddingHorizontal: 16,
paddingTop: 8
},
diagnosticsTitleRow: {
alignItems: "center",
flexDirection: "row",
justifyContent: "space-between"
},
diagnosticsTitle: {
color: "#111827",
fontSize: 17,
fontWeight: "700"
},
diagnosticsPill: {
backgroundColor: "#eef2ff",
borderRadius: 999,
color: "#3730a3",
fontSize: 12,
fontWeight: "700",
overflow: "hidden",
paddingHorizontal: 10,
paddingVertical: 4
},
diagnosticsServer: {
color: "#475569",
fontSize: 12,
marginTop: 4
},
diagnosticsMetaRow: {
flexDirection: "row",
gap: 8,
marginTop: 8
},
diagnosticsMeta: {
backgroundColor: "#f8fafc",
borderColor: "#e2e8f0",
borderRadius: 999,
borderWidth: StyleSheet.hairlineWidth,
color: "#334155",
fontSize: 11,
fontWeight: "600",
overflow: "hidden",
paddingHorizontal: 8,
paddingVertical: 3
},
latestLog: {
color: "#111827",
fontFamily: Platform.select({ ios: "Menlo", default: "monospace" }),
fontSize: 11,
lineHeight: 15,
marginTop: 8
},
nativeTabsContainer: {
backgroundColor: "#fff"
},
nativeTabScreen: {
backgroundColor: "#fff"
},
webTabs: {
flex: 1
},
webTabBar: {
alignItems: "center",
backgroundColor: "rgba(255,255,255,0.92)",
borderTopColor: "#e5e7eb",
borderTopWidth: StyleSheet.hairlineWidth,
flexDirection: "row",
minHeight: 72,
paddingBottom: 12,
paddingTop: 8
},
webTabButton: {
alignItems: "center",
flex: 1,
justifyContent: "center",
minHeight: 44
},
webTabContent: {
flex: 1
},
webTabLabel: {
color: "#64748b",
fontSize: 12,
fontWeight: "700"
},
webTabLabelActive: {
color: "#0f172a"
}
});