Skip to content

Commit 7fcf9cb

Browse files
konraddysputKonrad Dysput
andcommitted
react-native: Enable native functions for Bridgeless react-native setup (#325)
Co-authored-by: Konrad Dysput <konrad.dysput@saucelabs.com>
1 parent 3363271 commit 7fcf9cb

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

packages/react-native/src/builder/BacktraceClientBuilder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ export class BacktraceClientBuilder extends BacktraceCoreClientBuilder<Backtrace
1414
constructor(clientSetup: BacktraceClientSetup) {
1515
super(clientSetup);
1616

17-
const debuggerAvailable = DebuggerHelper.isConnected();
1817
this.addAttributeProvider(new ReactNativeAttributeProvider());
19-
if (debuggerAvailable) {
18+
if (!DebuggerHelper.isNativeBridgeEnabled()) {
2019
return;
2120
}
2221

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
import { NativeModules } from 'react-native';
2+
13
export class DebuggerHelper {
2-
public static isConnected(): boolean {
3-
return !(global as unknown as { nativeCallSyncHook: boolean }).nativeCallSyncHook;
4+
/**
5+
* Detects if the native bridge between JavaScript and native is available.
6+
* @returns true if the native bridge is available. Otherwise false.
7+
*/
8+
public static isNativeBridgeEnabled(): boolean {
9+
// in the bridgeless mode, we always have access to the native layer - there is no risk
10+
// on returning true.
11+
const isBridgeless = !NativeModules.UIManager;
12+
if (isBridgeless) {
13+
return true;
14+
}
15+
16+
return !!(global as unknown as { nativeCallSyncHook: boolean }).nativeCallSyncHook;
417
}
518
}

packages/react-native/src/crashReporter/CrashReporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class CrashReporter {
2929
return false;
3030
}
3131

32-
if (DebuggerHelper.isConnected()) {
32+
if (!DebuggerHelper.isNativeBridgeEnabled()) {
3333
return false;
3434
}
3535

packages/react-native/src/handlers/android/AndroidUnhandledExceptionHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class AndroidUnhandledExceptionHandler extends UnhandledExceptionHandler
1313
if (!this._unhandledExceptionHandler) {
1414
return;
1515
}
16-
if (DebuggerHelper.isConnected()) {
16+
if (!DebuggerHelper.isNativeBridgeEnabled()) {
1717
return;
1818
}
1919

0 commit comments

Comments
 (0)