patch `expo-notifications` to clear badge (#4475)
parent
d85c8a0976
commit
808dd3569d
|
@ -1,5 +1,5 @@
|
||||||
diff --git a/node_modules/expo-notifications/android/build.gradle b/node_modules/expo-notifications/android/build.gradle
|
diff --git a/node_modules/expo-notifications/android/build.gradle b/node_modules/expo-notifications/android/build.gradle
|
||||||
index d233e1f..cc2f856 100644
|
index b863077..8b5209e 100644
|
||||||
--- a/node_modules/expo-notifications/android/build.gradle
|
--- a/node_modules/expo-notifications/android/build.gradle
|
||||||
+++ b/node_modules/expo-notifications/android/build.gradle
|
+++ b/node_modules/expo-notifications/android/build.gradle
|
||||||
@@ -32,6 +32,7 @@ dependencies {
|
@@ -32,6 +32,7 @@ dependencies {
|
||||||
|
@ -10,6 +10,31 @@ index d233e1f..cc2f856 100644
|
||||||
|
|
||||||
if (project.findProject(':expo-modules-test-core')) {
|
if (project.findProject(':expo-modules-test-core')) {
|
||||||
testImplementation project(':expo-modules-test-core')
|
testImplementation project(':expo-modules-test-core')
|
||||||
|
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt
|
||||||
|
index 63a46c5..f911834 100644
|
||||||
|
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt
|
||||||
|
+++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt
|
||||||
|
@@ -1,5 +1,6 @@
|
||||||
|
package expo.modules.notifications.badge
|
||||||
|
|
||||||
|
+import android.app.NotificationManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import me.leolin.shortcutbadger.ShortcutBadgeException
|
||||||
|
@@ -12,7 +13,12 @@ object BadgeHelper {
|
||||||
|
|
||||||
|
fun setBadgeCount(context: Context, badgeCount: Int): Boolean {
|
||||||
|
return try {
|
||||||
|
- ShortcutBadger.applyCountOrThrow(context.applicationContext, badgeCount)
|
||||||
|
+ if (badgeCount == 0) {
|
||||||
|
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
+ notificationManager.cancelAll()
|
||||||
|
+ } else {
|
||||||
|
+ ShortcutBadger.applyCountOrThrow(context.applicationContext, badgeCount)
|
||||||
|
+ }
|
||||||
|
BadgeHelper.badgeCount = badgeCount
|
||||||
|
true
|
||||||
|
} catch (e: ShortcutBadgeException) {
|
||||||
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java
|
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java
|
||||||
index 0af7fe0..8f2c8d8 100644
|
index 0af7fe0..8f2c8d8 100644
|
||||||
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java
|
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java
|
||||||
|
@ -46,7 +71,7 @@ index 0af7fe0..8f2c8d8 100644
|
||||||
try {
|
try {
|
||||||
return payload.getString(TITLE_KEY);
|
return payload.getString(TITLE_KEY);
|
||||||
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java
|
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java
|
||||||
index f1fed19..80afe9e 100644
|
index f1fed19..012757b 100644
|
||||||
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java
|
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java
|
||||||
+++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java
|
+++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java
|
||||||
@@ -20,6 +20,7 @@ import expo.modules.notifications.notifications.enums.NotificationPriority;
|
@@ -20,6 +20,7 @@ import expo.modules.notifications.notifications.enums.NotificationPriority;
|
||||||
|
|
|
@ -7,3 +7,8 @@ in `onMessageReceived` are sent to the module for handling.
|
||||||
|
|
||||||
It also allows us to set the Android notification channel ID from the notification `data`, rather
|
It also allows us to set the Android notification channel ID from the notification `data`, rather
|
||||||
than the `notification` object in the payload.
|
than the `notification` object in the payload.
|
||||||
|
|
||||||
|
### `setBadgeCountAsync` fix on Android
|
||||||
|
|
||||||
|
`ShortcutBadger`'s `setCount` doesn't work for clearing the badge on Android for some reason. Instead, let's use the
|
||||||
|
Android API for clearing the badge.
|
||||||
|
|
Loading…
Reference in New Issue