Skip to content

Commit cd3dd96

Browse files
committed
Fix React Native Expo integration
1 parent f23182f commit cd3dd96

35 files changed

Lines changed: 747 additions & 142 deletions

eslint.config.mjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,5 @@ export default defineConfig(
4141
"vitest/valid-describe-callback": "off",
4242
"vitest/no-done-callback": "warn"
4343
}
44-
},
45-
{
46-
files: ["packages/react-native/src/plugins/ReactNativeEnvironmentInfoPlugin.ts"],
47-
rules: {
48-
"@typescript-eslint/no-require-imports": "off"
49-
}
5044
}
5145
);

example/expo/App.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
22
import { NavigationContainer } from "@react-navigation/native";
33
import Constants from "expo-constants";
4+
import * as Device from "expo-device";
45
import { GlassView } from "expo-glass-effect";
6+
import * as SplashScreen from "expo-splash-screen";
57
import { StatusBar } from "expo-status-bar";
68
import { useEffect, useMemo, useState } from "react";
79
import { Platform, StyleSheet, Text, View } from "react-native";
@@ -30,21 +32,29 @@ function TabIcon({ label, focused }: { label: string; focused: boolean }) {
3032
/**
3133
* Resolves the dev server URL based on the current platform.
3234
* - Web: localhost works directly.
33-
* - iOS Simulator: shares the host Mac's network.
34-
* - Real iOS device: needs the dev machine's IP, extracted from Expo's hostUri.
35+
* - iOS Simulator: localhost reaches the host Mac.
36+
* - Android Emulator: 10.0.2.2 reaches the host machine.
37+
* - Real devices: need the dev machine's IP, extracted from Expo's hostUri.
3538
*/
3639
function getServerUrl(): string {
37-
if (__DEV__ && Platform.OS !== "web") {
38-
const hostUri = Constants.expoConfig?.hostUri;
39-
if (hostUri) {
40-
try {
41-
const hostname = new URL(`http://${hostUri}`).hostname;
42-
return `http://${hostname}:7110`;
43-
} catch {
44-
// Fall through to default
45-
}
40+
if (!__DEV__ || Platform.OS === "web") {
41+
return "http://localhost:7110";
42+
}
43+
44+
if (!Device.isDevice) {
45+
return Platform.OS === "android" ? "http://10.0.2.2:7110" : "http://localhost:7110";
46+
}
47+
48+
const hostUri = Constants.expoConfig?.hostUri;
49+
if (hostUri) {
50+
try {
51+
const hostname = new URL(`http://${hostUri}`).hostname;
52+
return `http://${hostname}:7110`;
53+
} catch {
54+
// Fall through to default
4655
}
4756
}
57+
4858
return "http://localhost:7110";
4959
}
5060

@@ -87,6 +97,7 @@ export default function App() {
8797
config.defaultTags.push("Example", "Expo");
8898
config.useSessions(true, 60000, true);
8999
});
100+
void SplashScreen.hideAsync();
90101
}, []);
91102

92103
return (

example/expo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This app tracks Expo SDK 56.
99
## Prerequisites
1010

1111
- Install dependencies from the repository root with `npm install`.
12-
- Run an Exceptionless server on `http://localhost:7110`, or update `getServerUrl()` in `App.tsx`.
12+
- Run an Exceptionless server on `http://localhost:7110`. The example uses localhost for web/iOS Simulator, `10.0.2.2` for Android Emulator, and Expo's `hostUri` for physical devices.
1313
- Use a development build for native iOS crash reporting.
1414

1515
## Run
@@ -58,7 +58,7 @@ The in-app Logs tab should show events being enqueued and sent to the configured
5858

5959
## Notes
6060

61-
- The example points at `http://localhost:7110` by default and derives the host IP for physical iOS devices when Expo provides `hostUri`.
61+
- The example points at `http://localhost:7110` by default and only derives the host IP for physical devices when Expo provides `hostUri`.
6262
- Native iOS crashes are written by the native module and submitted on the next launch.
6363
- Android currently exercises JavaScript events only; Android native crash reporting is not implemented yet.
6464
- Generated native folders are intentionally ignored by `example/expo/.gitignore`; run `npm run prebuild --workspace=example/expo` or `npm run ios --workspace=example/expo` to recreate them locally.

example/expo/app.json

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,44 @@
44
"slug": "exceptionless-expo-example",
55
"version": "3.0.0",
66
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
78
"scheme": "exceptionless-expo",
89
"userInterfaceStyle": "light",
10+
"splash": {
11+
"image": "./assets/splash.png",
12+
"resizeMode": "contain",
13+
"backgroundColor": "#ffffff"
14+
},
915
"ios": {
1016
"supportsTablet": true,
11-
"bundleIdentifier": "com.exceptionless.expo.example"
17+
"bundleIdentifier": "com.exceptionless.expo.example",
18+
"icon": "./assets/icon.png"
1219
},
1320
"android": {
14-
"package": "com.exceptionless.expo.example"
21+
"package": "com.exceptionless.expo.example",
22+
"adaptiveIcon": {
23+
"foregroundImage": "./assets/adaptive-icon.png",
24+
"monochromeImage": "./assets/adaptive-icon-monochrome.png",
25+
"backgroundColor": "#ffffff"
26+
}
1527
},
1628
"web": {
17-
"bundler": "metro"
29+
"bundler": "metro",
30+
"favicon": "./assets/favicon.png"
1831
},
19-
"plugins": ["@exceptionless/react-native/expo-plugin", "expo-status-bar"],
32+
"plugins": [
33+
"@exceptionless/react-native/expo-plugin",
34+
"expo-status-bar",
35+
[
36+
"expo-splash-screen",
37+
{
38+
"backgroundColor": "#ffffff",
39+
"image": "./assets/splash-icon.png",
40+
"imageWidth": 190,
41+
"resizeMode": "contain"
42+
}
43+
]
44+
],
2045
"experiments": {
2146
"tsconfigPaths": true
2247
}
22.2 KB
Loading
178 KB
Loading

example/expo/assets/favicon.png

16.2 KB
Loading

example/expo/assets/icon.png

151 KB
Loading
1.85 MB
Loading
136 KB
Loading

0 commit comments

Comments
 (0)