Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ public void onClick(INotificationClickEvent event) {
};

private void removeObservers() {
if(!oneSignalInitDone) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can we try a test for this?

Logging.debug("OneSignal React-Native SDK not initialized yet. Could not remove observers.", null);
return;
}

this.removePermissionObserver();
this.removePushSubscriptionObserver();
this.removeUserStateObserver();
}

private void removeHandlers() {
if (hasAddedInAppMessageClickListener) {
OneSignal.getInAppMessages().removeClickListener(rnInAppClickListener);
hasAddedInAppMessageClickListener = false;
Expand Down Expand Up @@ -212,7 +215,6 @@ public RNOneSignal(ReactApplicationContext reactContext) {

// Clean up previous instance if it exists (handles reload scenario)
if (currentInstance != null && currentInstance != this) {
currentInstance.removeHandlers();
currentInstance.removeObservers();
}
currentInstance = this;
Expand All @@ -226,7 +228,6 @@ public String getName() {

@Override
public void onHostDestroy() {
removeHandlers();
removeObservers();
}

Expand All @@ -238,7 +239,6 @@ public void onHostResume() {}

@Override
public void onCatalystInstanceDestroy() {
removeHandlers();
removeObservers();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here.

}

Expand All @@ -254,15 +254,14 @@ public void initialize(String appId) {
return;
}

oneSignalInitDone = true;

if (context == null) {
// in some cases, especially when react-native-navigation is installed,
// the activity can be null, so we can initialize with the context instead
context = mReactApplicationContext.getApplicationContext();
}

OneSignal.initWithContext(context, appId);
oneSignalInitDone = true;
}

@ReactMethod
Expand Down
Loading