expo-notifications 0.28.19 → 0.29.1

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 (128) hide show
  1. package/CHANGELOG.md +39 -15
  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/handling/NotificationsHandler.kt +3 -1
  15. package/android/src/main/java/expo/modules/notifications/notifications/handling/SingleNotificationHandlerTask.java +2 -4
  16. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/INotificationContent.kt +2 -2
  17. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationBuilder.kt +1 -9
  18. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationListener.java +1 -1
  19. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationTrigger.kt +19 -0
  20. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationAction.java +3 -0
  21. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationCategory.java +2 -0
  22. package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java +21 -48
  23. package/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.kt +1 -1
  24. package/android/src/main/java/expo/modules/notifications/notifications/model/triggers/FirebaseNotificationTrigger.kt +11 -3
  25. package/android/src/main/java/expo/modules/notifications/notifications/presentation/ExpoNotificationPresentationModule.kt +11 -1
  26. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/BaseNotificationBuilder.kt +148 -0
  27. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.kt +97 -28
  28. package/android/src/main/java/expo/modules/notifications/notifications/scheduling/NotificationScheduler.kt +26 -8
  29. package/android/src/main/java/expo/modules/notifications/notifications/triggers/NotificationTriggers.kt +195 -0
  30. package/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt +11 -6
  31. package/android/src/main/java/expo/modules/notifications/service/delegates/ExpoHandlingDelegate.kt +11 -0
  32. package/android/src/main/java/expo/modules/notifications/service/delegates/ExpoPresentationDelegate.kt +14 -12
  33. package/android/src/main/java/expo/modules/notifications/service/delegates/ExpoSchedulingDelegate.kt +5 -0
  34. package/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt +13 -2
  35. package/build/NotificationPermissions.d.ts +3 -14
  36. package/build/NotificationPermissions.d.ts.map +1 -1
  37. package/build/NotificationPermissions.js +1 -16
  38. package/build/NotificationPermissions.js.map +1 -1
  39. package/build/NotificationPermissions.types.d.ts +0 -5
  40. package/build/NotificationPermissions.types.d.ts.map +1 -1
  41. package/build/NotificationPermissions.types.js.map +1 -1
  42. package/build/NotificationScheduler.types.d.ts +32 -11
  43. package/build/NotificationScheduler.types.d.ts.map +1 -1
  44. package/build/NotificationScheduler.types.js.map +1 -1
  45. package/build/Notifications.types.d.ts +101 -39
  46. package/build/Notifications.types.d.ts.map +1 -1
  47. package/build/Notifications.types.js +15 -0
  48. package/build/Notifications.types.js.map +1 -1
  49. package/build/NotificationsEmitter.d.ts +6 -6
  50. package/build/NotificationsEmitter.d.ts.map +1 -1
  51. package/build/NotificationsEmitter.js +8 -4
  52. package/build/NotificationsEmitter.js.map +1 -1
  53. package/build/NotificationsHandler.d.ts.map +1 -1
  54. package/build/NotificationsHandler.js +2 -2
  55. package/build/NotificationsHandler.js.map +1 -1
  56. package/build/TokenEmitter.d.ts +3 -3
  57. package/build/TokenEmitter.d.ts.map +1 -1
  58. package/build/TokenEmitter.js +5 -3
  59. package/build/TokenEmitter.js.map +1 -1
  60. package/build/Tokens.types.d.ts +10 -13
  61. package/build/Tokens.types.d.ts.map +1 -1
  62. package/build/Tokens.types.js.map +1 -1
  63. package/build/getDevicePushTokenAsync.d.ts.map +1 -1
  64. package/build/getDevicePushTokenAsync.js +2 -0
  65. package/build/getDevicePushTokenAsync.js.map +1 -1
  66. package/build/getDevicePushTokenAsync.web.d.ts.map +1 -1
  67. package/build/getDevicePushTokenAsync.web.js +2 -1
  68. package/build/getDevicePushTokenAsync.web.js.map +1 -1
  69. package/build/getExpoPushTokenAsync.d.ts.map +1 -1
  70. package/build/getExpoPushTokenAsync.js +2 -5
  71. package/build/getExpoPushTokenAsync.js.map +1 -1
  72. package/build/index.d.ts.map +1 -1
  73. package/build/index.js +9 -0
  74. package/build/index.js.map +1 -1
  75. package/build/scheduleNotificationAsync.d.ts +1 -1
  76. package/build/scheduleNotificationAsync.d.ts.map +1 -1
  77. package/build/scheduleNotificationAsync.js +155 -110
  78. package/build/scheduleNotificationAsync.js.map +1 -1
  79. package/build/setBadgeCountAsync.d.ts +1 -1
  80. package/build/setBadgeCountAsync.js +1 -1
  81. package/build/setBadgeCountAsync.js.map +1 -1
  82. package/build/setNotificationCategoryAsync.d.ts +2 -3
  83. package/build/setNotificationCategoryAsync.d.ts.map +1 -1
  84. package/build/setNotificationCategoryAsync.js +2 -3
  85. package/build/setNotificationCategoryAsync.js.map +1 -1
  86. package/build/warnOfExpoGoPushUsage.d.ts +2 -0
  87. package/build/warnOfExpoGoPushUsage.d.ts.map +1 -0
  88. package/build/warnOfExpoGoPushUsage.js +9 -0
  89. package/build/warnOfExpoGoPushUsage.js.map +1 -0
  90. package/ios/EXNotifications/Building/EXNotificationBuilder.m +4 -10
  91. package/ios/EXNotifications/Notifications/Categories/EXNotificationCategoriesModule.m +15 -43
  92. package/ios/EXNotifications/Notifications/EXNotificationCenterDelegate.m +4 -6
  93. package/ios/EXNotifications/Notifications/EXNotificationSerializer.m +11 -24
  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 +14 -9
  105. package/src/NotificationsHandler.ts +9 -4
  106. package/src/TokenEmitter.ts +7 -5
  107. package/src/Tokens.types.ts +10 -13
  108. package/src/getDevicePushTokenAsync.ts +2 -0
  109. package/src/getDevicePushTokenAsync.web.ts +2 -1
  110. package/src/getExpoPushTokenAsync.ts +2 -8
  111. package/src/index.ts +13 -0
  112. package/src/scheduleNotificationAsync.ts +198 -152
  113. package/src/setBadgeCountAsync.ts +1 -1
  114. package/src/setNotificationCategoryAsync.ts +2 -3
  115. package/src/warnOfExpoGoPushUsage.ts +12 -0
  116. package/tsconfig.json +1 -1
  117. package/android/src/main/java/expo/modules/notifications/notifications/channels/AndroidXNotificationsChannelsProvider.java +0 -38
  118. package/android/src/main/java/expo/modules/notifications/notifications/channels/NotificationsChannelsProvider.java +0 -13
  119. package/android/src/main/java/expo/modules/notifications/notifications/interfaces/NotificationTrigger.java +0 -16
  120. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/BaseNotificationBuilder.java +0 -50
  121. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/CategoryAwareNotificationBuilder.java +0 -81
  122. package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ChannelAwareNotificationBuilder.java +0 -134
  123. package/android/src/main/java/expo/modules/notifications/notifications/triggers/ChannelAwareTrigger.java +0 -49
  124. package/android/src/main/java/expo/modules/notifications/notifications/triggers/DailyTrigger.java +0 -76
  125. package/android/src/main/java/expo/modules/notifications/notifications/triggers/DateTrigger.java +0 -64
  126. package/android/src/main/java/expo/modules/notifications/notifications/triggers/TimeIntervalTrigger.java +0 -87
  127. package/android/src/main/java/expo/modules/notifications/notifications/triggers/WeeklyTrigger.java +0 -85
  128. package/android/src/main/java/expo/modules/notifications/notifications/triggers/YearlyTrigger.java +0 -94
package/CHANGELOG.md CHANGED
@@ -10,23 +10,45 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 0.28.19 — 2024-10-22
13
+ ## 0.29.1 — 2024-10-24
14
14
 
15
- ### 🐛 Bug fixes
15
+ _This version does not introduce any user-facing changes._
16
16
 
17
- - [android] fix: allow data message to control notification appearance ([#32162](https://github.com/expo/expo/pull/32162) by [@vonovak](https://github.com/vonovak))
17
+ ## 0.29.0 2024-10-22
18
+
19
+ ### 🛠 Breaking changes
18
20
 
19
- ## 0.28.18 2024-10-01
21
+ - 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))
22
+ - Simplify calendar trigger input types. ([#31598](https://github.com/expo/expo/pull/31598) by [@douglowder](https://github.com/douglowder))
20
23
 
21
24
  ### 🎉 New features
22
25
 
23
26
  - Add clearLastNotificationResponseAsync to API. ([#31607](https://github.com/expo/expo/pull/31607) by [@douglowder](https://github.com/douglowder))
27
+ - New monthly trigger type for scheduled notifications. ([#31823](https://github.com/expo/expo/pull/31823) by [@douglowder](https://github.com/douglowder))
24
28
 
25
29
  ### 🐛 Bug fixes
26
30
 
31
+ - [android] fix: allow data message to control notification appearance ([#32162](https://github.com/expo/expo/pull/32162) by [@vonovak](https://github.com/vonovak))
32
+ - [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))
33
+ - [android] `createNotificationChannel` could return incorrect channel information ([#32000](https://github.com/expo/expo/pull/32000) by [@vonovak](https://github.com/vonovak))
34
+ - [android] fix notifications with `ChannelAwareTrigger` not being presented ([#31999](https://github.com/expo/expo/pull/31999) by [@vonovak](https://github.com/vonovak))
35
+ - export `PermissionStatus` as value, not as type ([#31968](https://github.com/expo/expo/pull/31968) by [@vonovak](https://github.com/vonovak))
36
+ - throw improved error on invalid subscription in removeNotificationSubscription ([#31842](https://github.com/expo/expo/pull/31842) by [@vonovak](https://github.com/vonovak))
27
37
  - [android] fix notifications actions not being presented ([#31795](https://github.com/expo/expo/pull/31795) by [@vonovak](https://github.com/vonovak))
38
+ - 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))
39
+ - [iOS] do not overwrite existing aps entitlement. ([#31892](https://github.com/expo/expo/pull/31892) by [@douglowder](https://github.com/douglowder))
40
+
41
+ ### 💡 Others
28
42
 
29
- ## 0.28.17 2024-09-17
43
+ - warn when using push tokens in Expo Go ([#32122](https://github.com/expo/expo/pull/32122) by [@vonovak](https://github.com/vonovak))
44
+ - [android] refactor trigger serialization ([#32032](https://github.com/expo/expo/pull/32032) by [@vonovak](https://github.com/vonovak))
45
+ - [android] simplify DateTrigger ([#32002](https://github.com/expo/expo/pull/32002) by [@vonovak](https://github.com/vonovak))
46
+ - [android] refactor ExpoNotificationBuilder ([#31838](https://github.com/expo/expo/pull/31838) by [@vonovak](https://github.com/vonovak))
47
+ - Warn about limited support in Expo Go ([#31573](https://github.com/expo/expo/pull/31573) by [@vonovak](https://github.com/vonovak))
48
+ - 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))
49
+ - [Android] Convert trigger Java classes to Kotlin. ([#31856](https://github.com/expo/expo/pull/31856) by [@douglowder](https://github.com/douglowder))
50
+
51
+ ## 0.28.17 - 2024-09-17
30
52
 
31
53
  ### 🐛 Bug fixes
32
54
 
@@ -34,55 +56,54 @@
34
56
  - [Android] fix local notifications with null trigger. ([#31157](https://github.com/expo/expo/pull/31157) by [@douglowder](https://github.com/douglowder))
35
57
  - [Android] Take `channelId` into account when presenting notifications. ([#31201](https://github.com/expo/expo/pull/31201) by [@vonovak](https://github.com/vonovak))
36
58
 
37
- ## 0.28.16 2024-08-21
59
+ ## 0.28.16 - 2024-08-21
38
60
 
39
61
  ### 🐛 Bug fixes
40
62
 
41
63
  - [Android] Fix content.data in scheduled notifications surfaced to JS. ([#31048](https://github.com/expo/expo/pull/31048) by [@douglowder](https://github.com/douglowder))
42
64
 
43
- ## 0.28.15 2024-08-05
65
+ ## 0.28.15 - 2024-08-05
44
66
 
45
67
  ### 🐛 Bug fixes
46
68
 
47
69
  - [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))
48
70
 
49
- ## 0.28.14 2024-07-30
71
+ ## 0.28.14 - 2024-07-30
50
72
 
51
73
  ### 🐛 Bug fixes
52
74
 
53
75
  - `useLastNotificationResponse` should have only one effect. ([#30653](https://github.com/expo/expo/pull/30653) by [@douglowder](https://github.com/douglowder))
54
76
 
55
- ## 0.28.13 2024-07-29
77
+ ## 0.28.13 - 2024-07-29
56
78
 
57
79
  ### 🐛 Bug fixes
58
80
 
59
81
  - [Android] map Expo and Firebase notifications correctly. ([#30615](https://github.com/expo/expo/pull/30615) by [@douglowder](https://github.com/douglowder))
60
- - [Android] Apply requested changes from #30615. ([#30658](https://github.com/expo/expo/pull/30615) by [@lukmccall](https://github.com/lukmccall))
61
82
 
62
- ## 0.28.12 2024-07-25
83
+ ## 0.28.12 - 2024-07-25
63
84
 
64
85
  ### 🐛 Bug fixes
65
86
 
66
87
  - [Android] Android 11 crash when click foreground notifications. ([#30207](https://github.com/expo/expo/pull/30207) by [@GrinZero](https://github.com/GrinZero))
67
88
  - 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))
68
89
 
69
- ## 0.28.11 2024-07-22
90
+ ## 0.28.11 - 2024-07-22
70
91
 
71
92
  ### 🐛 Bug fixes
72
93
 
73
94
  - [Android] Fix serialization of vibration pattern. ([#30495](https://github.com/expo/expo/pull/30495) by [@douglowder](https://github.com/douglowder))
74
95
 
75
- ## 0.28.10 2024-07-15
96
+ ## 0.28.10 - 2024-07-15
76
97
 
77
98
  ### 🐛 Bug fixes
78
99
 
79
100
  - [Android] fix getLastNotificationResponseAsync. ([#30301](https://github.com/expo/expo/pull/30301) by [@douglowder](https://github.com/douglowder))
80
101
 
81
- ## 0.28.9 2024-06-12
102
+ ## 0.28.9 - 2024-06-12
82
103
 
83
104
  _This version does not introduce any user-facing changes._
84
105
 
85
- ## 0.28.8 2024-06-10
106
+ ## 0.28.8 - 2024-06-10
86
107
 
87
108
  ### 🐛 Bug fixes
88
109
 
@@ -112,6 +133,8 @@ _This version does not introduce any user-facing changes._
112
133
 
113
134
  - [Android] Correctly map response in useLastNotificationResponse hook. ([#28938](https://github.com/expo/expo/pull/28938) by [@douglowder](https://github.com/douglowder))
114
135
 
136
+ ## 0.28.3 — 2024-05-16
137
+
115
138
  ### 💡 Others
116
139
 
117
140
  - [iOS] Add support for `interruptionLevel`. ([#28921](https://github.com/expo/expo/pull/28921) by [@lukmccall](https://github.com/lukmccall))
@@ -286,6 +309,7 @@ _This version does not introduce any user-facing changes._
286
309
 
287
310
  ### 🛠 Breaking changes
288
311
 
312
+ - remove `usePermissions` hook ([#31905](https://github.com/expo/expo/pull/31905) by [@vonovak](https://github.com/vonovak))
289
313
  - [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))
290
314
 
291
315
  ### 🐛 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.19'
5
+ version = '0.29.1'
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.19'
18
+ versionName '0.29.1'
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()}
@@ -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;