expo-notifications 0.28.17 → 0.29.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 (127) hide show
  1. package/CHANGELOG.md +46 -11
  2. package/README.md +1 -3
  3. package/android/build.gradle +3 -2
  4. package/android/src/main/java/expo/modules/notifications/Utils.kt +2 -2
  5. package/android/src/main/java/expo/modules/notifications/notifications/NotificationManager.java +8 -0
  6. package/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java +7 -49
  7. package/android/src/main/java/expo/modules/notifications/notifications/background/BackgroundRemoteNotificationTaskConsumer.java +2 -1
  8. package/android/src/main/java/expo/modules/notifications/notifications/channels/AbstractNotificationsChannelsProvider.java +0 -60
  9. package/android/src/main/java/expo/modules/notifications/notifications/channels/AndroidXNotificationsChannelsProvider.kt +26 -0
  10. package/android/src/main/java/expo/modules/notifications/notifications/channels/NotificationsChannelsProvider.kt +13 -0
  11. package/android/src/main/java/expo/modules/notifications/notifications/channels/managers/AndroidXNotificationsChannelGroupManager.java +1 -2
  12. package/android/src/main/java/expo/modules/notifications/notifications/channels/managers/AndroidXNotificationsChannelManager.java +4 -1
  13. package/android/src/main/java/expo/modules/notifications/notifications/debug/DebugLogging.kt +2 -2
  14. package/android/src/main/java/expo/modules/notifications/notifications/emitting/NotificationsEmitter.kt +5 -0
  15. package/android/src/main/java/expo/modules/notifications/notifications/handling/NotificationsHandler.kt +3 -1
  16. package/android/src/main/java/expo/modules/notifications/notifications/handling/SingleNotificationHandlerTask.java +2 -4
  17. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/INotificationContent.kt +2 -2
  18. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationBuilder.kt +1 -9
  19. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationListener.java +1 -1
  20. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationTrigger.kt +19 -0
  21. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationAction.java +3 -0
  22. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationCategory.java +2 -0
  23. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java +21 -48
  24. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.kt +69 -0
  25. package/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.kt +20 -30
  26. package/android/src/main/java/expo/modules/notifications/notifications/model/triggers/FirebaseNotificationTrigger.kt +11 -3
  27. package/android/src/main/java/expo/modules/notifications/notifications/presentation/ExpoNotificationPresentationModule.kt +11 -1
  28. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/BaseNotificationBuilder.kt +148 -0
  29. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.kt +98 -29
  30. package/android/src/main/java/expo/modules/notifications/notifications/scheduling/NotificationScheduler.kt +26 -8
  31. package/android/src/main/java/expo/modules/notifications/notifications/triggers/NotificationTriggers.kt +195 -0
  32. package/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt +11 -6
  33. package/android/src/main/java/expo/modules/notifications/service/delegates/ExpoHandlingDelegate.kt +11 -0
  34. package/android/src/main/java/expo/modules/notifications/service/delegates/ExpoPresentationDelegate.kt +14 -12
  35. package/android/src/main/java/expo/modules/notifications/service/delegates/ExpoSchedulingDelegate.kt +5 -0
  36. package/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt +13 -2
  37. package/build/NotificationPermissions.d.ts +3 -14
  38. package/build/NotificationPermissions.d.ts.map +1 -1
  39. package/build/NotificationPermissions.js +1 -16
  40. package/build/NotificationPermissions.js.map +1 -1
  41. package/build/NotificationPermissions.types.d.ts +0 -5
  42. package/build/NotificationPermissions.types.d.ts.map +1 -1
  43. package/build/NotificationPermissions.types.js.map +1 -1
  44. package/build/NotificationScheduler.types.d.ts +32 -11
  45. package/build/NotificationScheduler.types.d.ts.map +1 -1
  46. package/build/NotificationScheduler.types.js.map +1 -1
  47. package/build/Notifications.types.d.ts +101 -39
  48. package/build/Notifications.types.d.ts.map +1 -1
  49. package/build/Notifications.types.js +15 -0
  50. package/build/Notifications.types.js.map +1 -1
  51. package/build/NotificationsEmitter.d.ts +16 -6
  52. package/build/NotificationsEmitter.d.ts.map +1 -1
  53. package/build/NotificationsEmitter.js +38 -5
  54. package/build/NotificationsEmitter.js.map +1 -1
  55. package/build/NotificationsHandler.d.ts.map +1 -1
  56. package/build/NotificationsHandler.js +2 -2
  57. package/build/NotificationsHandler.js.map +1 -1
  58. package/build/TokenEmitter.d.ts +3 -3
  59. package/build/TokenEmitter.d.ts.map +1 -1
  60. package/build/TokenEmitter.js +3 -3
  61. package/build/TokenEmitter.js.map +1 -1
  62. package/build/Tokens.types.d.ts +10 -13
  63. package/build/Tokens.types.d.ts.map +1 -1
  64. package/build/Tokens.types.js.map +1 -1
  65. package/build/getDevicePushTokenAsync.web.d.ts.map +1 -1
  66. package/build/getDevicePushTokenAsync.web.js +2 -1
  67. package/build/getDevicePushTokenAsync.web.js.map +1 -1
  68. package/build/getExpoPushTokenAsync.d.ts.map +1 -1
  69. package/build/getExpoPushTokenAsync.js +2 -5
  70. package/build/getExpoPushTokenAsync.js.map +1 -1
  71. package/build/index.d.ts.map +1 -1
  72. package/build/index.js +9 -0
  73. package/build/index.js.map +1 -1
  74. package/build/scheduleNotificationAsync.d.ts +1 -1
  75. package/build/scheduleNotificationAsync.d.ts.map +1 -1
  76. package/build/scheduleNotificationAsync.js +155 -110
  77. package/build/scheduleNotificationAsync.js.map +1 -1
  78. package/build/setBadgeCountAsync.d.ts +1 -1
  79. package/build/setBadgeCountAsync.js +1 -1
  80. package/build/setBadgeCountAsync.js.map +1 -1
  81. package/build/setNotificationCategoryAsync.d.ts +2 -3
  82. package/build/setNotificationCategoryAsync.d.ts.map +1 -1
  83. package/build/setNotificationCategoryAsync.js +2 -3
  84. package/build/setNotificationCategoryAsync.js.map +1 -1
  85. package/build/useLastNotificationResponse.d.ts.map +1 -1
  86. package/build/useLastNotificationResponse.js +5 -1
  87. package/build/useLastNotificationResponse.js.map +1 -1
  88. package/ios/EXNotifications/Building/EXNotificationBuilder.m +4 -10
  89. package/ios/EXNotifications/Notifications/Categories/EXNotificationCategoriesModule.m +15 -43
  90. package/ios/EXNotifications/Notifications/EXNotificationCenterDelegate.m +4 -6
  91. package/ios/EXNotifications/Notifications/EXNotificationSerializer.m +11 -24
  92. package/ios/EXNotifications/Notifications/Emitter/EXNotificationsEmitter.h +1 -0
  93. package/ios/EXNotifications/Notifications/Emitter/EXNotificationsEmitter.m +8 -1
  94. package/ios/EXNotifications/Notifications/Scheduling/EXNotificationSchedulerModule.m +16 -0
  95. package/ios/EXNotifications/Permissions/EXUserFacingNotificationsPermissionsRequester.m +11 -27
  96. package/ios/EXNotifications.podspec +3 -1
  97. package/package.json +12 -9
  98. package/plugin/build/withNotificationsIOS.js +3 -1
  99. package/plugin/src/withNotificationsIOS.ts +3 -1
  100. package/src/NotificationPermissions.ts +2 -24
  101. package/src/NotificationPermissions.types.ts +0 -5
  102. package/src/NotificationScheduler.types.ts +41 -22
  103. package/src/Notifications.types.ts +109 -52
  104. package/src/NotificationsEmitter.ts +45 -9
  105. package/src/NotificationsHandler.ts +9 -4
  106. package/src/TokenEmitter.ts +5 -5
  107. package/src/Tokens.types.ts +10 -13
  108. package/src/getDevicePushTokenAsync.web.ts +2 -1
  109. package/src/getExpoPushTokenAsync.ts +2 -8
  110. package/src/index.ts +13 -0
  111. package/src/scheduleNotificationAsync.ts +198 -152
  112. package/src/setBadgeCountAsync.ts +1 -1
  113. package/src/setNotificationCategoryAsync.ts +2 -3
  114. package/src/useLastNotificationResponse.ts +5 -0
  115. package/tsconfig.json +1 -1
  116. package/android/src/main/java/expo/modules/notifications/notifications/channels/AndroidXNotificationsChannelsProvider.java +0 -38
  117. package/android/src/main/java/expo/modules/notifications/notifications/channels/NotificationsChannelsProvider.java +0 -13
  118. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationTrigger.java +0 -16
  119. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/BaseNotificationBuilder.java +0 -50
  120. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/CategoryAwareNotificationBuilder.java +0 -81
  121. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ChannelAwareNotificationBuilder.java +0 -134
  122. package/android/src/main/java/expo/modules/notifications/notifications/triggers/ChannelAwareTrigger.java +0 -49
  123. package/android/src/main/java/expo/modules/notifications/notifications/triggers/DailyTrigger.java +0 -76
  124. package/android/src/main/java/expo/modules/notifications/notifications/triggers/DateTrigger.java +0 -64
  125. package/android/src/main/java/expo/modules/notifications/notifications/triggers/TimeIntervalTrigger.java +0 -87
  126. package/android/src/main/java/expo/modules/notifications/notifications/triggers/WeeklyTrigger.java +0 -85
  127. package/android/src/main/java/expo/modules/notifications/notifications/triggers/YearlyTrigger.java +0 -94
package/CHANGELOG.md CHANGED
@@ -10,7 +10,40 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 0.28.17 — 2024-09-17
13
+ ## 0.29.0 — 2024-10-22
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Bumped iOS deployment target to 15.1. ([#30840](https://github.com/expo/expo/pull/30840), [#30862](https://github.com/expo/expo/pull/30862) by [@tsapeta](https://github.com/tsapeta))
18
+ - Simplify calendar trigger input types. ([#31598](https://github.com/expo/expo/pull/31598) by [@douglowder](https://github.com/douglowder))
19
+
20
+ ### 🎉 New features
21
+
22
+ - Add clearLastNotificationResponseAsync to API. ([#31607](https://github.com/expo/expo/pull/31607) by [@douglowder](https://github.com/douglowder))
23
+ - New monthly trigger type for scheduled notifications. ([#31823](https://github.com/expo/expo/pull/31823) by [@douglowder](https://github.com/douglowder))
24
+
25
+ ### 🐛 Bug fixes
26
+
27
+ - [android] fix: allow data message to control notification appearance ([#32162](https://github.com/expo/expo/pull/32162) by [@vonovak](https://github.com/vonovak))
28
+ - [ios] fix crash if expo-update reload happens while Notifications.requestPermissionsAsync() is showing native dialog ([#32096](https://github.com/expo/expo/pull/32096) by [@mfazekas](https://github.com/mfazekas))
29
+ - [android] `createNotificationChannel` could return incorrect channel information ([#32000](https://github.com/expo/expo/pull/32000) by [@vonovak](https://github.com/vonovak))
30
+ - [android] fix notifications with `ChannelAwareTrigger` not being presented ([#31999](https://github.com/expo/expo/pull/31999) by [@vonovak](https://github.com/vonovak))
31
+ - export `PermissionStatus` as value, not as type ([#31968](https://github.com/expo/expo/pull/31968) by [@vonovak](https://github.com/vonovak))
32
+ - throw improved error on invalid subscription in removeNotificationSubscription ([#31842](https://github.com/expo/expo/pull/31842) by [@vonovak](https://github.com/vonovak))
33
+ - [android] fix notifications actions not being presented ([#31795](https://github.com/expo/expo/pull/31795) by [@vonovak](https://github.com/vonovak))
34
+ - Add missing `react` and `react-native` peer dependencies for isolated modules. ([#30478](https://github.com/expo/expo/pull/30478) by [@byCedric](https://github.com/byCedric))
35
+ - [iOS] do not overwrite existing aps entitlement. ([#31892](https://github.com/expo/expo/pull/31892) by [@douglowder](https://github.com/douglowder))
36
+
37
+ ### 💡 Others
38
+
39
+ - [android] refactor trigger serialization ([#32032](https://github.com/expo/expo/pull/32032) by [@vonovak](https://github.com/vonovak))
40
+ - [android] simplify DateTrigger ([#32002](https://github.com/expo/expo/pull/32002) by [@vonovak](https://github.com/vonovak))
41
+ - [android] refactor ExpoNotificationBuilder ([#31838](https://github.com/expo/expo/pull/31838) by [@vonovak](https://github.com/vonovak))
42
+ - Warn about limited support in Expo Go ([#31573](https://github.com/expo/expo/pull/31573) by [@vonovak](https://github.com/vonovak))
43
+ - Keep using the legacy event emitter as the module is not fully migrated to Expo Modules API. ([#28946](https://github.com/expo/expo/pull/28946) by [@tsapeta](https://github.com/tsapeta))
44
+ - [Android] Convert trigger Java classes to Kotlin. ([#31856](https://github.com/expo/expo/pull/31856) by [@douglowder](https://github.com/douglowder))
45
+
46
+ ## 0.28.17 - 2024-09-17
14
47
 
15
48
  ### 🐛 Bug fixes
16
49
 
@@ -18,55 +51,54 @@
18
51
  - [Android] fix local notifications with null trigger. ([#31157](https://github.com/expo/expo/pull/31157) by [@douglowder](https://github.com/douglowder))
19
52
  - [Android] Take `channelId` into account when presenting notifications. ([#31201](https://github.com/expo/expo/pull/31201) by [@vonovak](https://github.com/vonovak))
20
53
 
21
- ## 0.28.16 2024-08-21
54
+ ## 0.28.16 - 2024-08-21
22
55
 
23
56
  ### 🐛 Bug fixes
24
57
 
25
58
  - [Android] Fix content.data in scheduled notifications surfaced to JS. ([#31048](https://github.com/expo/expo/pull/31048) by [@douglowder](https://github.com/douglowder))
26
59
 
27
- ## 0.28.15 2024-08-05
60
+ ## 0.28.15 - 2024-08-05
28
61
 
29
62
  ### 🐛 Bug fixes
30
63
 
31
64
  - [Android] Eliminate unsupported types when processing notification intents from onCreate/onNewIntent. ([#30750](https://github.com/expo/expo/pull/30750) by [@douglowder](https://github.com/douglowder))
32
65
 
33
- ## 0.28.14 2024-07-30
66
+ ## 0.28.14 - 2024-07-30
34
67
 
35
68
  ### 🐛 Bug fixes
36
69
 
37
70
  - `useLastNotificationResponse` should have only one effect. ([#30653](https://github.com/expo/expo/pull/30653) by [@douglowder](https://github.com/douglowder))
38
71
 
39
- ## 0.28.13 2024-07-29
72
+ ## 0.28.13 - 2024-07-29
40
73
 
41
74
  ### 🐛 Bug fixes
42
75
 
43
76
  - [Android] map Expo and Firebase notifications correctly. ([#30615](https://github.com/expo/expo/pull/30615) by [@douglowder](https://github.com/douglowder))
44
- - [Android] Apply requested changes from #30615. ([#30658](https://github.com/expo/expo/pull/30615) by [@lukmccall](https://github.com/lukmccall))
45
77
 
46
- ## 0.28.12 2024-07-25
78
+ ## 0.28.12 - 2024-07-25
47
79
 
48
80
  ### 🐛 Bug fixes
49
81
 
50
82
  - [Android] Android 11 crash when click foreground notifications. ([#30207](https://github.com/expo/expo/pull/30207) by [@GrinZero](https://github.com/GrinZero))
51
83
  - Notification's textInput content would contain `placeholder` instead of the actual user input ([#27479](https://github.com/expo/expo/pull/27479) by [@Victor-FT](https://github.com/Victor-FT))
52
84
 
53
- ## 0.28.11 2024-07-22
85
+ ## 0.28.11 - 2024-07-22
54
86
 
55
87
  ### 🐛 Bug fixes
56
88
 
57
89
  - [Android] Fix serialization of vibration pattern. ([#30495](https://github.com/expo/expo/pull/30495) by [@douglowder](https://github.com/douglowder))
58
90
 
59
- ## 0.28.10 2024-07-15
91
+ ## 0.28.10 - 2024-07-15
60
92
 
61
93
  ### 🐛 Bug fixes
62
94
 
63
95
  - [Android] fix getLastNotificationResponseAsync. ([#30301](https://github.com/expo/expo/pull/30301) by [@douglowder](https://github.com/douglowder))
64
96
 
65
- ## 0.28.9 2024-06-12
97
+ ## 0.28.9 - 2024-06-12
66
98
 
67
99
  _This version does not introduce any user-facing changes._
68
100
 
69
- ## 0.28.8 2024-06-10
101
+ ## 0.28.8 - 2024-06-10
70
102
 
71
103
  ### 🐛 Bug fixes
72
104
 
@@ -96,6 +128,8 @@ _This version does not introduce any user-facing changes._
96
128
 
97
129
  - [Android] Correctly map response in useLastNotificationResponse hook. ([#28938](https://github.com/expo/expo/pull/28938) by [@douglowder](https://github.com/douglowder))
98
130
 
131
+ ## 0.28.3 — 2024-05-16
132
+
99
133
  ### 💡 Others
100
134
 
101
135
  - [iOS] Add support for `interruptionLevel`. ([#28921](https://github.com/expo/expo/pull/28921) by [@lukmccall](https://github.com/lukmccall))
@@ -270,6 +304,7 @@ _This version does not introduce any user-facing changes._
270
304
 
271
305
  ### 🛠 Breaking changes
272
306
 
307
+ - remove `usePermissions` hook ([#31905](https://github.com/expo/expo/pull/31905) by [@vonovak](https://github.com/vonovak))
273
308
  - [android] Set the "notification number" (sometimes used to increment badge count on some launchers) from the notification payload `badge` field. ([#17171](https://github.com/expo/expo/pull/17171) by [@danstepanov](https://github.com/danstepanov))
274
309
 
275
310
  ### 🐛 Bug fixes
package/README.md CHANGED
@@ -50,7 +50,7 @@ In order to be able to receive push notifications on the device:
50
50
 
51
51
  ### Configure for Android
52
52
 
53
- In order to be able to receive push notifications on the device ensure that your project is set up for Firebase. For more information on how to do it, see [this guide](https://docs.expo.dev/guides/setup-native-firebase/#bare-workflow-setup).
53
+ In order to be able to receive push notifications on the device ensure that your project is set up for Firebase. For more information on how to do it, see [this guide](https://docs.expo.dev/guides/using-firebase/#install-and-initialize-react-native-firebase).
54
54
 
55
55
  This module requires permission to subscribe to device boot. It's used to setup the scheduled notifications right after the device (re)starts. The `RECEIVE_BOOT_COMPLETED` permission is added automatically.
56
56
 
@@ -825,7 +825,6 @@ An optional object of conforming to the following interface:
825
825
  allowCriticalAlerts?: boolean;
826
826
  provideAppNotificationSettings?: boolean;
827
827
  allowProvisional?: boolean;
828
- allowAnnouncements?: boolean;
829
828
  }
830
829
  }
831
830
  ```
@@ -849,7 +848,6 @@ export function requestPermissionsAsync() {
849
848
  allowAlert: true,
850
849
  allowBadge: true,
851
850
  allowSound: true,
852
- allowAnnouncements: true,
853
851
  },
854
852
  });
855
853
  }
@@ -1,7 +1,8 @@
1
1
  apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-parcelize'
2
3
 
3
4
  group = 'host.exp.exponent'
4
- version = '0.28.17'
5
+ version = '0.29.0'
5
6
 
6
7
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
8
  apply from: expoModulesCorePlugin
@@ -14,7 +15,7 @@ android {
14
15
  namespace "expo.modules.notifications"
15
16
  defaultConfig {
16
17
  versionCode 21
17
- versionName '0.28.17'
18
+ versionName '0.29.0'
18
19
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19
20
  }
20
21
 
@@ -90,11 +90,11 @@ internal fun isValidJSONString(test: Any?): Boolean {
90
90
  when (test is String) {
91
91
  true -> {
92
92
  try {
93
- JSONObject(test as String)
93
+ JSONObject(test)
94
94
  return true
95
95
  } catch (objectEx: JSONException) {
96
96
  try {
97
- JSONArray(test as String)
97
+ JSONArray(test)
98
98
  return true
99
99
  } catch (arrayEx: JSONException) {
100
100
  return false
@@ -30,6 +30,10 @@ public class NotificationManager implements SingletonModule, expo.modules.notifi
30
30
  public NotificationManager() {
31
31
  mListenerReferenceMap = new WeakHashMap<>();
32
32
 
33
+ // TODO @vonovak there's a chain of listeners:
34
+ // ExpoHandlingDelegate -> NotificationManager -> NotificationsEmitter
35
+ // -> NotificationsHandler
36
+ // it seems it could be shorter?
33
37
  // Registers this singleton instance in static ExpoHandlingDelegate listeners collection.
34
38
  // Since it doesn't hold strong reference to the object this should be safe.
35
39
  ExpoHandlingDelegate.Companion.addListener(this);
@@ -81,6 +85,10 @@ public class NotificationManager implements SingletonModule, expo.modules.notifi
81
85
  * Calls {@link NotificationListener#onNotificationReceived(Notification)} on all values
82
86
  * of {@link NotificationManager#mListenerReferenceMap}.
83
87
  *
88
+ * In practice, that means calling {@link NotificationsEmitter} (just emits an event to JS) and
89
+ * {@link NotificationsHandler} which calls `handleNotification` in JS to determine the behavior.
90
+ * Then `SingleNotificationHandlerTask.processNotificationWithBehavior` may present it.
91
+ *
84
92
  * @param notification Notification received
85
93
  */
86
94
  public void onNotificationReceived(Notification notification) {
@@ -32,6 +32,7 @@ import expo.modules.notifications.notifications.model.triggers.FirebaseNotificat
32
32
 
33
33
  import expo.modules.notifications.notifications.triggers.DailyTrigger;
34
34
  import expo.modules.notifications.notifications.triggers.DateTrigger;
35
+ import expo.modules.notifications.notifications.triggers.MonthlyTrigger;
35
36
  import expo.modules.notifications.notifications.triggers.TimeIntervalTrigger;
36
37
  import expo.modules.notifications.notifications.triggers.WeeklyTrigger;
37
38
  import expo.modules.notifications.notifications.triggers.YearlyTrigger;
@@ -57,11 +58,12 @@ public class NotificationSerializer {
57
58
  public static Bundle toBundle(NotificationRequest request) {
58
59
  Bundle serializedRequest = new Bundle();
59
60
  serializedRequest.putString("identifier", request.getIdentifier());
60
- serializedRequest.putBundle("trigger", toBundle(request.getTrigger()));
61
+ NotificationTrigger requestTrigger = request.getTrigger();
62
+ serializedRequest.putBundle("trigger", requestTrigger == null ? null : requestTrigger.toBundle());
61
63
  Bundle content = toBundle(request.getContent());
62
64
  Bundle existingContentData = content.getBundle("data");
63
65
  if (existingContentData == null) {
64
- if(request.getTrigger() instanceof FirebaseNotificationTrigger trigger) {
66
+ if(requestTrigger instanceof FirebaseNotificationTrigger trigger) {
65
67
  RemoteMessage message = trigger.getRemoteMessage();
66
68
  RemoteMessage.Notification notification = message.getNotification();
67
69
  Map<String, String> data = message.getData();
@@ -76,8 +78,8 @@ public class NotificationSerializer {
76
78
  content.putBundle("data", toBundle(data));
77
79
  }
78
80
  } else if(
79
- request.getTrigger() instanceof SchedulableNotificationTrigger ||
80
- request.getTrigger() == null
81
+ requestTrigger instanceof SchedulableNotificationTrigger ||
82
+ requestTrigger == null
81
83
  ) {
82
84
  JSONObject body = request.getContent().getBody();
83
85
  if (body != null) {
@@ -101,7 +103,7 @@ public class NotificationSerializer {
101
103
  public static Bundle toBundle(INotificationContent content) {
102
104
  Bundle serializedContent = new Bundle();
103
105
  serializedContent.putString("title", content.getTitle());
104
- serializedContent.putString("subtitle", content.getSubtitle());
106
+ serializedContent.putString("subtitle", content.getSubText());
105
107
  serializedContent.putString("body", content.getText());
106
108
  if (content.getColor() != null) {
107
109
  serializedContent.putString("color", String.format("#%08X", content.getColor().intValue()));
@@ -186,50 +188,6 @@ public class NotificationSerializer {
186
188
  return result;
187
189
  }
188
190
 
189
- private static Bundle toBundle(@Nullable NotificationTrigger trigger) {
190
- if (trigger == null) {
191
- return null;
192
- }
193
- Bundle bundle = new Bundle();
194
- if (trigger instanceof FirebaseNotificationTrigger) {
195
- bundle.putString("type", "push");
196
- bundle.putBundle("remoteMessage", RemoteMessageSerializer.toBundle(((FirebaseNotificationTrigger) trigger).getRemoteMessage()));
197
- } else if (trigger instanceof TimeIntervalTrigger) {
198
- bundle.putString("type", "timeInterval");
199
- bundle.putBoolean("repeats", ((TimeIntervalTrigger) trigger).isRepeating());
200
- bundle.putLong("seconds", ((TimeIntervalTrigger) trigger).getTimeInterval());
201
- } else if (trigger instanceof DateTrigger) {
202
- bundle.putString("type", "date");
203
- bundle.putBoolean("repeats", false);
204
- bundle.putLong("value", ((DateTrigger) trigger).getTriggerDate().getTime());
205
- } else if (trigger instanceof DailyTrigger) {
206
- bundle.putString("type", "daily");
207
- bundle.putInt("hour", ((DailyTrigger) trigger).getHour());
208
- bundle.putInt("minute", ((DailyTrigger) trigger).getMinute());
209
- } else if (trigger instanceof WeeklyTrigger) {
210
- bundle.putString("type", "weekly");
211
- bundle.putInt("weekday", ((WeeklyTrigger) trigger).getWeekday());
212
- bundle.putInt("hour", ((WeeklyTrigger) trigger).getHour());
213
- bundle.putInt("minute", ((WeeklyTrigger) trigger).getMinute());
214
- } else if (trigger instanceof YearlyTrigger) {
215
- bundle.putString("type", "yearly");
216
- bundle.putInt("day", ((YearlyTrigger) trigger).getDay());
217
- bundle.putInt("month", ((YearlyTrigger) trigger).getMonth());
218
- bundle.putInt("hour", ((YearlyTrigger) trigger).getHour());
219
- bundle.putInt("minute", ((YearlyTrigger) trigger).getMinute());
220
- } else {
221
- bundle.putString("type", "unknown");
222
- }
223
- bundle.putString("channelId", getChannelId(trigger));
224
-
225
- return bundle;
226
- }
227
-
228
- @Nullable
229
- private static String getChannelId(NotificationTrigger trigger) {
230
- return trigger.getNotificationChannel();
231
- }
232
-
233
191
  @NotNull
234
192
  public static Bundle toResponseBundleFromExtras(Bundle extras) {
235
193
  Bundle serializedContent = new Bundle();
@@ -25,9 +25,10 @@ import expo.modules.interfaces.taskManager.TaskManagerUtilsInterface;
25
25
  /**
26
26
  * Represents a task to be run when the app is receives a remote push
27
27
  * notification. Map of current tasks is maintained in {@link FirebaseMessagingDelegate}.
28
+ *
29
+ * Instances are instantiated by expo task manager, after being registered in ExpoBackgroundNotificationTasksModule
28
30
  */
29
31
  public class BackgroundRemoteNotificationTaskConsumer extends TaskConsumer implements TaskConsumerInterface {
30
- private static final String TAG = BackgroundRemoteNotificationTaskConsumer.class.getSimpleName();
31
32
  private static final String NOTIFICATION_KEY = "notification";
32
33
 
33
34
  private TaskInterface mTask;
@@ -2,25 +2,13 @@ package expo.modules.notifications.notifications.channels;
2
2
 
3
3
  import android.content.Context;
4
4
 
5
- import expo.modules.core.ModuleRegistry;
6
5
  import expo.modules.core.interfaces.InternalModule;
7
6
 
8
7
  import java.util.Collections;
9
8
  import java.util.List;
10
9
 
11
- import expo.modules.notifications.notifications.channels.managers.NotificationsChannelGroupManager;
12
- import expo.modules.notifications.notifications.channels.managers.NotificationsChannelManager;
13
- import expo.modules.notifications.notifications.channels.serializers.NotificationsChannelGroupSerializer;
14
- import expo.modules.notifications.notifications.channels.serializers.NotificationsChannelSerializer;
15
-
16
10
  public abstract class AbstractNotificationsChannelsProvider implements NotificationsChannelsProvider, InternalModule {
17
11
  protected final Context mContext;
18
- private NotificationsChannelManager mChannelManager;
19
- private NotificationsChannelGroupManager mChannelGroupManager;
20
- private NotificationsChannelSerializer mChannelSerializer;
21
- private NotificationsChannelGroupSerializer mChannelGroupSerializer;
22
-
23
- private ModuleRegistry mModuleRegistry;
24
12
 
25
13
  public AbstractNotificationsChannelsProvider(Context context) {
26
14
  mContext = context;
@@ -30,52 +18,4 @@ public abstract class AbstractNotificationsChannelsProvider implements Notificat
30
18
  return Collections.singletonList(NotificationsChannelsProvider.class);
31
19
  }
32
20
 
33
- @Override
34
- public void onCreate(ModuleRegistry moduleRegistry) {
35
- mModuleRegistry = moduleRegistry;
36
- }
37
-
38
- public final ModuleRegistry getModuleRegistry() {
39
- return mModuleRegistry;
40
- }
41
-
42
- @Override
43
- public final NotificationsChannelManager getChannelManager() {
44
- if (mChannelManager == null) {
45
- mChannelManager = createChannelManager();
46
- }
47
- return mChannelManager;
48
- }
49
-
50
- @Override
51
- public final NotificationsChannelGroupManager getGroupManager() {
52
- if (mChannelGroupManager == null) {
53
- mChannelGroupManager = createChannelGroupManager();
54
- }
55
- return mChannelGroupManager;
56
- }
57
-
58
- @Override
59
- public final NotificationsChannelSerializer getChannelSerializer() {
60
- if (mChannelSerializer == null) {
61
- mChannelSerializer = createChannelSerializer();
62
- }
63
- return mChannelSerializer;
64
- }
65
-
66
- @Override
67
- public final NotificationsChannelGroupSerializer getGroupSerializer() {
68
- if (mChannelGroupSerializer == null) {
69
- mChannelGroupSerializer = createChannelGroupSerializer();
70
- }
71
- return mChannelGroupSerializer;
72
- }
73
-
74
- protected abstract NotificationsChannelManager createChannelManager();
75
-
76
- protected abstract NotificationsChannelGroupManager createChannelGroupManager();
77
-
78
- protected abstract NotificationsChannelSerializer createChannelSerializer();
79
-
80
- protected abstract NotificationsChannelGroupSerializer createChannelGroupSerializer();
81
21
  }
@@ -0,0 +1,26 @@
1
+ package expo.modules.notifications.notifications.channels
2
+
3
+ import android.content.Context
4
+ import expo.modules.notifications.notifications.channels.managers.AndroidXNotificationsChannelGroupManager
5
+ import expo.modules.notifications.notifications.channels.managers.AndroidXNotificationsChannelManager
6
+ import expo.modules.notifications.notifications.channels.serializers.ExpoNotificationsChannelGroupSerializer
7
+ import expo.modules.notifications.notifications.channels.serializers.ExpoNotificationsChannelSerializer
8
+
9
+ class AndroidXNotificationsChannelsProvider(context: Context) : AbstractNotificationsChannelsProvider(context) {
10
+
11
+ override val groupManager by lazy {
12
+ AndroidXNotificationsChannelGroupManager(context)
13
+ }
14
+
15
+ override val channelManager by lazy {
16
+ AndroidXNotificationsChannelManager(context, groupManager)
17
+ }
18
+
19
+ override val channelSerializer by lazy {
20
+ ExpoNotificationsChannelSerializer()
21
+ }
22
+
23
+ override val groupSerializer by lazy {
24
+ ExpoNotificationsChannelGroupSerializer(channelSerializer)
25
+ }
26
+ }
@@ -0,0 +1,13 @@
1
+ package expo.modules.notifications.notifications.channels
2
+
3
+ import expo.modules.notifications.notifications.channels.managers.NotificationsChannelGroupManager
4
+ import expo.modules.notifications.notifications.channels.managers.NotificationsChannelManager
5
+ import expo.modules.notifications.notifications.channels.serializers.NotificationsChannelGroupSerializer
6
+ import expo.modules.notifications.notifications.channels.serializers.NotificationsChannelSerializer
7
+
8
+ interface NotificationsChannelsProvider {
9
+ val channelManager: NotificationsChannelManager
10
+ val groupManager: NotificationsChannelGroupManager
11
+ val channelSerializer: NotificationsChannelSerializer
12
+ val groupSerializer: NotificationsChannelGroupSerializer
13
+ }
@@ -54,10 +54,9 @@ public class AndroidXNotificationsChannelGroupManager implements NotificationsCh
54
54
  // Processing options
55
55
  @RequiresApi(api = Build.VERSION_CODES.O)
56
56
  protected void configureGroupWithOptions(Object maybeGroup, ReadableArguments groupOptions) {
57
- if (!(maybeGroup instanceof NotificationChannelGroup)) {
57
+ if (!(maybeGroup instanceof NotificationChannelGroup group)) {
58
58
  return;
59
59
  }
60
- NotificationChannelGroup group = (NotificationChannelGroup) maybeGroup;
61
60
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
62
61
  if (groupOptions.containsKey(DESCRIPTION_KEY)) {
63
62
  group.setDescription(groupOptions.getString(DESCRIPTION_KEY));
@@ -80,7 +80,10 @@ public class AndroidXNotificationsChannelManager implements NotificationsChannel
80
80
  NotificationChannel channel = new NotificationChannel(channelId, name, importance);
81
81
  configureChannelWithOptions(channel, channelOptions);
82
82
  mNotificationManager.createNotificationChannel(channel);
83
- return channel;
83
+ // We return the channel given by mNotificationManager, not the one we created.
84
+ // see "Note that the created channel may differ from this value." ("this value" = the one we provided)
85
+ // https://developer.android.com/reference/android/app/NotificationManager#createNotificationChannel(android.app.NotificationChannel)
86
+ return mNotificationManager.getNotificationChannel(channelId);
84
87
  }
85
88
 
86
89
  // Processing options
@@ -70,10 +70,10 @@ object DebugLogging {
70
70
  """
71
71
  $caller:
72
72
  notification.notificationRequest.content.title: ${notification.notificationRequest.content.title}
73
- notification.notificationRequest.content.subtitle: ${notification.notificationRequest.content.subtitle}
73
+ notification.notificationRequest.content.subText: ${notification.notificationRequest.content.subText}
74
74
  notification.notificationRequest.content.text: ${notification.notificationRequest.content.text}
75
75
  notification.notificationRequest.content.sound: ${notification.notificationRequest.content.soundName}
76
- notification.notificationRequest.content.channelID: ${notification.notificationRequest.trigger.notificationChannel}
76
+ notification.notificationRequest.content.channelID: ${notification.notificationRequest.trigger.getNotificationChannel()}
77
77
  notification.notificationRequest.content.body: ${notification.notificationRequest.content.body}
78
78
  notification.notificationRequest.content.color: ${notification.notificationRequest.content.color}
79
79
  notification.notificationRequest.content.vibrationPattern: ${notification.notificationRequest.content.vibrationPattern?.contentToString()}
@@ -41,6 +41,11 @@ open class NotificationsEmitter : Module(), NotificationListener {
41
41
  AsyncFunction<Bundle?>("getLastNotificationResponseAsync") {
42
42
  lastNotificationResponseBundle
43
43
  }
44
+
45
+ AsyncFunction("clearLastNotificationResponseAsync") {
46
+ lastNotificationResponseBundle = null
47
+ null
48
+ }
44
49
  }
45
50
 
46
51
  /**
@@ -99,7 +99,7 @@ open class NotificationsHandler : Module(), NotificationListener {
99
99
  ?: throw NotificationWasAlreadyHandledException(identifier)
100
100
 
101
101
  with(behavior) {
102
- task.handleResponse(
102
+ task.processNotificationWithBehavior(
103
103
  NotificationBehavior(shouldShowAlert, shouldPlaySound, shouldSetBadge, priority),
104
104
  promise
105
105
  )
@@ -110,6 +110,8 @@ open class NotificationsHandler : Module(), NotificationListener {
110
110
  * Callback called by [NotificationManager] to inform its listeners of new messages.
111
111
  * Starts up a new [SingleNotificationHandlerTask] which will take it on from here.
112
112
  *
113
+ * SingleNotificationHandlerTask.processNotificationWithBehavior can then present it
114
+ *
113
115
  * @param notification Notification received
114
116
  */
115
117
  override fun onNotificationReceived(notification: Notification) {
@@ -34,7 +34,6 @@ public class SingleNotificationHandlerTask {
34
34
  private Handler mHandler;
35
35
  private EventEmitter mEventEmitter;
36
36
  private Notification mNotification;
37
- private NotificationBehavior mBehavior;
38
37
  private Context mContext;
39
38
  private NotificationsHandler mDelegate;
40
39
 
@@ -88,12 +87,11 @@ public class SingleNotificationHandlerTask {
88
87
  * @param behavior Behavior requested by the app
89
88
  * @param promise Promise to fulfill once the behavior is applied to the notification.
90
89
  */
91
- /* package */ void handleResponse(NotificationBehavior behavior, final Promise promise) {
92
- mBehavior = behavior;
90
+ /* package */ void processNotificationWithBehavior(final NotificationBehavior behavior, final Promise promise) {
93
91
  mHandler.post(new Runnable() {
94
92
  @Override
95
93
  public void run() {
96
- NotificationsService.Companion.present(mContext, mNotification, mBehavior, new ResultReceiver(mHandler) {
94
+ NotificationsService.Companion.present(mContext, mNotification, behavior, new ResultReceiver(mHandler) {
97
95
  @Override
98
96
  protected void onReceiveResult(int resultCode, Bundle resultData) {
99
97
  super.onReceiveResult(resultCode, resultData);
@@ -17,7 +17,7 @@ import org.json.JSONObject
17
17
  interface INotificationContent : Parcelable {
18
18
  val title: String?
19
19
  val text: String?
20
- val subtitle: String?
20
+ val subText: String?
21
21
  val badgeCount: Number?
22
22
  val shouldPlayDefaultSound: Boolean
23
23
 
@@ -27,7 +27,7 @@ interface INotificationContent : Parcelable {
27
27
  val shouldUseDefaultVibrationPattern: Boolean
28
28
  val vibrationPattern: LongArray?
29
29
  val body: JSONObject?
30
- val priority: NotificationPriority
30
+ val priority: NotificationPriority?
31
31
  val color: Number?
32
32
  val isAutoDismiss: Boolean
33
33
  val categoryId: String?
@@ -8,14 +8,6 @@ import expo.modules.notifications.notifications.model.NotificationBehavior
8
8
  * on a [NotificationContent] spec.
9
9
  */
10
10
  interface NotificationBuilder {
11
- /**
12
- * Pass in a [Notification] based on which the Android notification should be based.
13
- *
14
- * @param notification [Notification] on which the notification should be based.
15
- * @return The same instance of [NotificationBuilder] updated with the notification.
16
- */
17
- fun setNotification(notification: Notification?): NotificationBuilder?
18
-
19
11
  /**
20
12
  * Pass in a [NotificationBehavior] if you want to override the behavior
21
13
  * of the notification, i.e. whether it should show a heads-up alert, set badge, etc.
@@ -23,7 +15,7 @@ interface NotificationBuilder {
23
15
  * @param behavior [NotificationBehavior] to which the presentation effect should conform.
24
16
  * @return The same instance of [NotificationBuilder] updated with the remote message.
25
17
  */
26
- fun setAllowedBehavior(behavior: NotificationBehavior?): NotificationBuilder?
18
+ fun setAllowedBehavior(behavior: NotificationBehavior?): NotificationBuilder
27
19
 
28
20
  /**
29
21
  * Builds the Android notification based on passed in data.
@@ -13,7 +13,7 @@ import expo.modules.notifications.notifications.model.NotificationResponse;
13
13
  */
14
14
  public interface NotificationListener {
15
15
  /**
16
- * Callback called when new notification is received.
16
+ * Callback called when new notification is received while the app is in foreground.
17
17
  *
18
18
  * @param notification Notification received
19
19
  */
@@ -0,0 +1,19 @@
1
+ package expo.modules.notifications.notifications.interfaces
2
+
3
+ import android.os.Bundle
4
+ import android.os.Parcelable
5
+
6
+ /**
7
+ * An interface specifying source of the notification, to be implemented
8
+ * by concrete classes.
9
+ */
10
+ interface NotificationTrigger : Parcelable {
11
+ // these are functions so that we're absolutely sure @Parcelize doesn't try to parcelize them
12
+ // (as opposed to if they were properties)
13
+
14
+ fun getNotificationChannel(): String? {
15
+ return null
16
+ }
17
+
18
+ fun toBundle(): Bundle
19
+ }
@@ -7,6 +7,9 @@ import java.io.Serializable;
7
7
 
8
8
  /**
9
9
  * A class representing a single notification action button.
10
+ *
11
+ * TODO vonovak: no need to implement serializable, parcelable is enough for storing
12
+ *
10
13
  */
11
14
  public class NotificationAction implements Parcelable, Serializable {
12
15
  private final String mIdentifier;
@@ -9,6 +9,8 @@ import java.util.List;
9
9
 
10
10
  /**
11
11
  * A class representing a collection of notification actions.
12
+ *
13
+ * TODO vonovak: no need to implement serializable, parcelable is enough for storing
12
14
  */
13
15
  public class NotificationCategory implements Parcelable, Serializable {
14
16
  private final String mIdentifier;