-
Notifications
You must be signed in to change notification settings - Fork 375
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
Skip creation of EventManager if module not loaded #1427
Open
srascar-bubble
wants to merge
1
commit into
OneSignal:main
Choose a base branch
from
srascar-bubble:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. ```
when this PR will be merged, some prediction I have the same problem |
diff --git a/node_modules/react-native-onesignal/dist/index.js b/node_modules/react-native-onesignal/dist/index.js
index 0958bde..74573a5 100644
--- a/node_modules/react-native-onesignal/dist/index.js
+++ b/node_modules/react-native-onesignal/dist/index.js
@@ -47,7 +47,12 @@ var NotificationReceivedEvent_1 = __importDefault(require("./events/Notification
exports.NotificationReceivedEvent = NotificationReceivedEvent_1.default;
var helpers_1 = require("./helpers");
var RNOneSignal = react_native_1.NativeModules.OneSignal;
-var eventManager = new EventManager_1.default(RNOneSignal);
+var eventManager;
+
+if ((0, helpers_1.isNativeModuleLoaded)(RNOneSignal)) {
+ eventManager = new EventManager_1.default(RNOneSignal);
+}
+
var OneSignal = /** @class */ (function () {
function OneSignal() {
}
diff --git a/node_modules/react-native-onesignal/src/index.ts b/node_modules/react-native-onesignal/src/index.ts
index 561dc0a..d57a4aa 100644
--- a/node_modules/react-native-onesignal/src/index.ts
+++ b/node_modules/react-native-onesignal/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;
|
@erickpiazza for the time being we apply the above patch
|
betohit
approved these changes
Oct 25, 2022
vctrlima
approved these changes
Oct 25, 2022
I guess this also fixes #1361. Two years and two approvals later, why hasn't this been merged? |
delki8
approved these changes
Nov 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Prevent the creation of a NativeEventEmitter with
null
as argumentDetails
Creating
EventManager
when the module is not loaded will generate the following errorMotivation
This change will affect most likely
expo
users.Since version 4.x of OneSignal,
EventManager
is always created which leads to the error abovewhen running the app in Expo go and IOS Simulator.
Manual testing
This change is