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

notifyReceivedToJS only when app is visible #694

Merged
merged 3 commits into from
Oct 28, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface Defs {
String TOKEN_RECEIVED_EVENT_NAME = "remoteNotificationsRegistered";

String NOTIFICATION_RECEIVED_EVENT_NAME = "notificationReceived";
String NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME = "notificationReceivedBackground";
String NOTIFICATION_OPENED_EVENT_NAME = "notificationOpened";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static com.wix.reactnativenotifications.Defs.NOTIFICATION_OPENED_EVENT_NAME;
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME;
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME;

public class PushNotification implements IPushNotification {

Expand Down Expand Up @@ -61,8 +62,10 @@ protected PushNotification(Context context, Bundle bundle, AppLifecycleFacade ap
public void onReceived() throws InvalidNotificationException {
if (!mAppLifecycleFacade.isAppVisible()) {
postNotification(null);
notifyReceivedBackgroundToJS();
} else {
notifyReceivedToJS();
}
notifyReceivedToJS();
}

@Override
Expand Down Expand Up @@ -204,6 +207,10 @@ private void notifyReceivedToJS() {
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_EVENT_NAME, mNotificationProps.asBundle(), mAppLifecycleFacade.getRunningReactContext());
}

private void notifyReceivedBackgroundToJS() {
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME, mNotificationProps.asBundle(), mAppLifecycleFacade.getRunningReactContext());
}

private void notifyOpenedToJS() {
Bundle response = new Bundle();
response.putBundle("notification", mNotificationProps.asBundle());
Expand Down