Skip to content
Closed
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
2 changes: 1 addition & 1 deletion examples/demo/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/events/EventManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ describe('EventManager', () => {
new EventManager(null as never);
expect(freshModule.onPermissionChanged).not.toHaveBeenCalled();
});

test('should not crash when event emitters are unavailable (Old Architecture)', () => {
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const moduleWithoutEmitters = {} as never;

expect(() => new EventManager(moduleWithoutEmitters)).not.toThrow();
expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining('Native event emitters are not available'),
);

consoleSpy.mockRestore();
});
});

describe('addEventListener', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/events/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export default class EventManager {
setupListeners() {
if (this.RNOneSignal == null) return;

if (typeof this.RNOneSignal.onPermissionChanged !== 'function') {
console.error(
'OneSignal: Native event emitters are not available. ' +
'Ensure the New Architecture (TurboModules) is enabled and the native module is rebuilt.',
);
return;
}

this.nativeSubscriptions.push(
this.RNOneSignal.onPermissionChanged((payload) => {
const typed = payload as { permission: boolean };
Expand Down
Loading