react-native-notify-kit 10.9.0 → 10.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +18 -0
  2. package/android/src/main/AndroidManifest.xml +11 -0
  3. package/android/src/main/java/app/notifee/core/EventBus.java +4 -0
  4. package/android/src/main/java/app/notifee/core/FullScreenNotificationActivity.java +76 -0
  5. package/android/src/main/java/app/notifee/core/InitialNotificationLedger.java +262 -0
  6. package/android/src/main/java/app/notifee/core/Notifee.java +142 -20
  7. package/android/src/main/java/app/notifee/core/NotificationManager.java +44 -6
  8. package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +14 -0
  9. package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +11 -2
  10. package/android/src/main/java/app/notifee/core/event/InitialNotificationEvent.java +15 -0
  11. package/android/src/main/kotlin/io/invertase/notifee/NotifeeApiModule.kt +23 -0
  12. package/android/src/test/java/app/notifee/core/NotifeeGetInitialNotificationTest.java +3805 -0
  13. package/android/src/test/java/io/invertase/notifee/PermissionRationaleTest.java +144 -0
  14. package/cli/package.json +1 -1
  15. package/dist/NotifeeApiModule.d.ts +1 -0
  16. package/dist/NotifeeApiModule.js +6 -0
  17. package/dist/NotifeeApiModule.js.map +1 -1
  18. package/dist/specs/NativeNotifeeModule.d.ts +1 -0
  19. package/dist/specs/NativeNotifeeModule.js.map +1 -1
  20. package/dist/types/Module.d.ts +29 -3
  21. package/dist/version.d.ts +1 -1
  22. package/dist/version.js +1 -1
  23. package/dist/version.js.map +1 -1
  24. package/ios/RNNotifee/NotifeeApiModule.mm +5 -0
  25. package/jest-mock.js +1 -0
  26. package/package.json +1 -1
  27. package/src/NotifeeApiModule.ts +8 -0
  28. package/src/specs/NativeNotifeeModule.ts +1 -0
  29. package/src/types/Module.ts +30 -3
  30. package/src/version.ts +1 -1
@@ -29,6 +29,14 @@ import java.util.UUID;
29
29
  public class NotificationPendingIntent {
30
30
  public static final String EVENT_TYPE_INTENT_KEY = "notifee_event_type";
31
31
  public static final String NOTIFICATION_ID_INTENT_KEY = "notification_id";
32
+
33
+ /**
34
+ * Random id shared by the Intents of one PendingIntent, or issued for a full-screen Intent, so a
35
+ * launch Intent can be matched with the interactions recorded by {@link
36
+ * InitialNotificationLedger}.
37
+ */
38
+ static final String PENDING_INTENT_ID_INTENT_KEY = "notifee_pending_intent_id";
39
+
32
40
  private static final String TAG = "NotificationPendingIntent";
33
41
 
34
42
  /**
@@ -74,6 +82,12 @@ public class NotificationPendingIntent {
74
82
  setIntentExtras(launchActivityIntent, eventType, notificationId, extraKeys, extraBundles);
75
83
  setIntentExtras(receiverIntent, eventType, notificationId, extraKeys, extraBundles);
76
84
 
85
+ String pendingIntentId = UUID.randomUUID().toString();
86
+ if (launchActivityIntent != null) {
87
+ launchActivityIntent.putExtra(PENDING_INTENT_ID_INTENT_KEY, pendingIntentId);
88
+ }
89
+ receiverIntent.putExtra(PENDING_INTENT_ID_INTENT_KEY, pendingIntentId);
90
+
77
91
  // Create pending intent with activities
78
92
  int uniqueInt = UUID.randomUUID().hashCode();
79
93
  Intent[] intents;
@@ -19,6 +19,7 @@ package app.notifee.core;
19
19
 
20
20
  import static app.notifee.core.NotificationPendingIntent.EVENT_TYPE_INTENT_KEY;
21
21
  import static app.notifee.core.NotificationPendingIntent.NOTIFICATION_ID_INTENT_KEY;
22
+ import static app.notifee.core.NotificationPendingIntent.PENDING_INTENT_ID_INTENT_KEY;
22
23
  import static app.notifee.core.event.NotificationEvent.TYPE_ACTION_PRESS;
23
24
  import static app.notifee.core.event.NotificationEvent.TYPE_PRESS;
24
25
 
@@ -98,7 +99,11 @@ public class NotificationReceiverHandler {
98
99
  }
99
100
 
100
101
  InitialNotificationEvent initialNotificationEvent =
101
- new InitialNotificationEvent(notificationModel, extras);
102
+ new InitialNotificationEvent(
103
+ notificationModel,
104
+ extras,
105
+ InitialNotificationLedger.recordTap(
106
+ intent.getStringExtra(PENDING_INTENT_ID_INTENT_KEY)));
102
107
  EventBus.postSticky(initialNotificationEvent);
103
108
 
104
109
  // Send event
@@ -127,7 +132,11 @@ public class NotificationReceiverHandler {
127
132
  EventBus.post(new NotificationEvent(TYPE_PRESS, notificationModel, extras));
128
133
 
129
134
  InitialNotificationEvent initialNotificationEvent =
130
- new InitialNotificationEvent(notificationModel, extras);
135
+ new InitialNotificationEvent(
136
+ notificationModel,
137
+ extras,
138
+ InitialNotificationLedger.recordTap(
139
+ intent.getStringExtra(PENDING_INTENT_ID_INTENT_KEY)));
131
140
  EventBus.postSticky(initialNotificationEvent);
132
141
 
133
142
  if (pressActionBundle == null) {
@@ -26,10 +26,21 @@ public class InitialNotificationEvent {
26
26
 
27
27
  private NotificationModel notificationModel;
28
28
  private Bundle extras;
29
+ private long tapSequence;
29
30
 
30
31
  public InitialNotificationEvent(NotificationModel notificationModel, Bundle extras) {
32
+ this(notificationModel, extras, 0);
33
+ }
34
+
35
+ /**
36
+ * @param tapSequence sequence number recorded for the tap that produced this event, or 0 when the
37
+ * tap is not tracked.
38
+ */
39
+ public InitialNotificationEvent(
40
+ NotificationModel notificationModel, Bundle extras, long tapSequence) {
31
41
  this.notificationModel = notificationModel;
32
42
  this.extras = extras;
43
+ this.tapSequence = tapSequence;
33
44
  }
34
45
 
35
46
  public NotificationModel getNotificationModel() {
@@ -40,6 +51,10 @@ public class InitialNotificationEvent {
40
51
  return extras;
41
52
  }
42
53
 
54
+ public long getTapSequence() {
55
+ return tapSequence;
56
+ }
57
+
43
58
  public Map<String, Object> toMap() {
44
59
  Map<String, Object> initialNotificationEventMap = new HashMap<>();
45
60
  initialNotificationEventMap.put("notificationModel", notificationModel.toBundle());
@@ -233,6 +233,29 @@ class NotifeeApiModule(reactContext: ReactApplicationContext) :
233
233
  }
234
234
  }
235
235
 
236
+ override fun shouldShowRequestPermissionRationale(promise: Promise) {
237
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
238
+ promise.resolve(false)
239
+ return
240
+ }
241
+
242
+ try {
243
+ val activity = getReactApplicationContext().getCurrentActivity()
244
+ if (activity == null) {
245
+ promise.reject(
246
+ "ERR_NO_ACTIVITY",
247
+ "A current Activity is required to query notification permission rationale.",
248
+ )
249
+ return
250
+ }
251
+ promise.resolve(
252
+ activity.shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS),
253
+ )
254
+ } catch (e: Exception) {
255
+ promise.reject(e)
256
+ }
257
+ }
258
+
236
259
  override fun requestPermission(permissions: ReadableMap, promise: Promise) {
237
260
  // permissions parameter is ignored on Android — only used by iOS
238
261
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {