From 603efcd2ffff896a1b4f3ed48611801074f466c4 Mon Sep 17 00:00:00 2001 From: Sylvain Rascar <87284168+srascar-bubble@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:46:58 +0100 Subject: [PATCH] Skip creation of EventManager if module not loaded This change will affect most likely `expo` users. Since version 4.x of OneSignal, `EventManager` is always created which leads to the following error when running the app in Expo go and IOS Simulator. ``` Invariant Violation: `new NativeEventEmitter()` requires a non-null argument. ``` --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 561dc0ad..d57a4aa6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,11 @@ import { InAppMessage, InAppMessageAction, InAppMessageLifecycleHandlerObject } import { isValidCallback, isNativeModuleLoaded } from './helpers'; const RNOneSignal = NativeModules.OneSignal; -const eventManager = new EventManager(RNOneSignal); +let eventManager: EventManager; + +if (isNativeModuleLoaded(RNOneSignal)) { + eventManager = new EventManager(RNOneSignal); +} // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose export type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6;