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

Fix: Notification click listener fires on cold start #1017

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

jennantilla
Copy link
Contributor

@jennantilla jennantilla commented Aug 29, 2024

Description

One Line Summary

Ensure notification click listener fires on cold start

Details

The native notification click listener is currently added on initialization, rather than when the listener method is explicitly called. This could lead to timing issues where the listener is added after the onClick event. Moving the listener out of initialization and into the bridge method follows other wrapper implementations.

Motivation

It was reported that on certain implementations of Ionic and Cordova apps, the notification click listener was not firing on cold start. Making this change fixes that issue and allows the listener to fire when the notification is clicked from cold start, background, and foreground app states.

Testing

Manual testing

Tested opening a notification while the app was both backgrounded and from a cold start. App build with Android Studio 2023.2.1 with a fresh install of the OneSignal example app on a Pixel 6 with Android 14.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

- Ensures that the notification click listener fires on app cold start
Copy link
Contributor

@emawby emawby left a comment

Choose a reason for hiding this comment

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

Do we always want to add ourselves as a click listener when the customer adds one? We should probably only do it once.

- Introduced a boolean flag to track whether the notification click listener has already been added
- Updated `addNotificationClickListener` method to only add the listener if it hasn't been added yet
Copy link
Contributor

@emawby emawby left a comment

Choose a reason for hiding this comment

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

Have you tested with hotreload? If you hotreload do we still only fire the callback once?

@jennantilla
Copy link
Contributor Author

jennantilla commented Sep 6, 2024

Good callout! I successfully tested adding the listener with hot reload: the callback only fires once.

@emawby emawby self-requested a review September 6, 2024 02:24
@jennantilla jennantilla merged commit 64883d2 into main Sep 6, 2024
3 checks passed
@jennantilla jennantilla deleted the fix/notification_click_listener_cold_start branch September 6, 2024 16:54
@jennantilla jennantilla mentioned this pull request Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants