Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native: Enable native functions for Bridgeless react-native setup #325

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/react-native/src/builder/BacktraceClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export class BacktraceClientBuilder extends BacktraceCoreClientBuilder<Backtrace
constructor(clientSetup: BacktraceClientSetup) {
super(clientSetup);

const debuggerAvailable = DebuggerHelper.isConnected();
this.addAttributeProvider(new ReactNativeAttributeProvider());
if (debuggerAvailable) {
if (!DebuggerHelper.isNativeBridgeEnabled()) {
return;
}

Expand Down
17 changes: 15 additions & 2 deletions packages/react-native/src/common/DebuggerHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { NativeModules } from 'react-native';

export class DebuggerHelper {
public static isConnected(): boolean {
return !(global as unknown as { nativeCallSyncHook: boolean }).nativeCallSyncHook;
/**
* Detects if the native bridge between JavaScript and native is available.
* @returns true if the native bridge is available. Otherwise false.
*/
public static isNativeBridgeEnabled(): boolean {
// in the bridgeless mode, we always have access to the native layer - there is no risk
// on returning true.
const isBridgeless = !NativeModules.UIManager;
if (isBridgeless) {
return true;
}

return !!(global as unknown as { nativeCallSyncHook: boolean }).nativeCallSyncHook;
}
}
2 changes: 1 addition & 1 deletion packages/react-native/src/crashReporter/CrashReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CrashReporter {
return false;
}

if (DebuggerHelper.isConnected()) {
if (!DebuggerHelper.isNativeBridgeEnabled()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AndroidUnhandledExceptionHandler extends UnhandledExceptionHandler
if (!this._unhandledExceptionHandler) {
return;
}
if (DebuggerHelper.isConnected()) {
if (!DebuggerHelper.isNativeBridgeEnabled()) {
return;
}

Expand Down
Loading