expo-notifications 0.28.18 → 0.28.19
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.
- package/CHANGELOG.md +6 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.kt +69 -0
- package/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.kt +20 -30
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 0.28.19 — 2024-10-22
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
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))
|
|
18
|
+
|
|
13
19
|
## 0.28.18 — 2024-10-01
|
|
14
20
|
|
|
15
21
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'host.exp.exponent'
|
|
4
|
-
version = '0.28.
|
|
4
|
+
version = '0.28.19'
|
|
5
5
|
|
|
6
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
7
|
apply from: expoModulesCorePlugin
|
|
@@ -14,7 +14,7 @@ android {
|
|
|
14
14
|
namespace "expo.modules.notifications"
|
|
15
15
|
defaultConfig {
|
|
16
16
|
versionCode 21
|
|
17
|
-
versionName '0.28.
|
|
17
|
+
versionName '0.28.19'
|
|
18
18
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
19
19
|
}
|
|
20
20
|
|
package/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.kt
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package expo.modules.notifications.notifications.model
|
|
2
|
+
|
|
3
|
+
import org.json.JSONArray
|
|
4
|
+
import org.json.JSONObject
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* In some scenarios, data-only push notifications are, in fact, presented.
|
|
8
|
+
* The presentation preferences are taken from the data payload.
|
|
9
|
+
*
|
|
10
|
+
* https://docs.expo.dev/versions/latest/sdk/notifications/#android-push-notification-payload-specification
|
|
11
|
+
* */
|
|
12
|
+
@JvmInline
|
|
13
|
+
value class NotificationData(private val data: Map<String, String>) {
|
|
14
|
+
val title: String?
|
|
15
|
+
get() = data["title"]
|
|
16
|
+
|
|
17
|
+
val message: String?
|
|
18
|
+
get() = data["message"]
|
|
19
|
+
|
|
20
|
+
val body: JSONObject?
|
|
21
|
+
get() = try {
|
|
22
|
+
data["body"]?.let { JSONObject(it) }
|
|
23
|
+
} catch (e: Exception) {
|
|
24
|
+
null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
val sound: String?
|
|
28
|
+
get() = data["sound"]
|
|
29
|
+
|
|
30
|
+
val shouldPlayDefaultSound: Boolean
|
|
31
|
+
get() = sound == null
|
|
32
|
+
|
|
33
|
+
val shouldUseDefaultVibrationPattern: Boolean
|
|
34
|
+
get() = data["vibrate"]?.toBoolean() == true
|
|
35
|
+
|
|
36
|
+
val isSticky: Boolean
|
|
37
|
+
get() = data["sticky"]?.toBoolean() ?: false
|
|
38
|
+
|
|
39
|
+
val vibrationPattern: LongArray?
|
|
40
|
+
get() = try {
|
|
41
|
+
data["vibrate"]?.let { vibrateString ->
|
|
42
|
+
JSONArray(vibrateString).let { jsonArray ->
|
|
43
|
+
LongArray(jsonArray.length()) { i ->
|
|
44
|
+
jsonArray.getLong(i)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (e: Exception) {
|
|
49
|
+
// most likely a boolean value that cannot be converted to a longArray
|
|
50
|
+
null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
val color: String? get() = data["color"]
|
|
54
|
+
|
|
55
|
+
val autoDismiss: Boolean
|
|
56
|
+
get() = data["autoDismiss"]?.toBoolean() ?: true
|
|
57
|
+
|
|
58
|
+
val categoryId: String?
|
|
59
|
+
get() = data["categoryId"]
|
|
60
|
+
|
|
61
|
+
val sticky: Boolean
|
|
62
|
+
get() = data["sticky"]?.toBoolean() ?: false
|
|
63
|
+
|
|
64
|
+
val subText: String?
|
|
65
|
+
get() = data["subtitle"]
|
|
66
|
+
|
|
67
|
+
val badge: Int?
|
|
68
|
+
get() = data["badge"]?.toIntOrNull()
|
|
69
|
+
}
|
|
@@ -8,7 +8,6 @@ import com.google.firebase.messaging.RemoteMessage
|
|
|
8
8
|
import expo.modules.notifications.notifications.enums.NotificationPriority
|
|
9
9
|
import expo.modules.notifications.notifications.interfaces.INotificationContent
|
|
10
10
|
import expo.modules.notifications.notifications.presentation.builders.downloadImage
|
|
11
|
-
import org.json.JSONObject
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* A POJO representing a remote notification content: title, message, body, etc.
|
|
@@ -21,6 +20,8 @@ class RemoteNotificationContent(private val remoteMessage: RemoteMessage) : INot
|
|
|
21
20
|
|
|
22
21
|
constructor(parcel: Parcel) : this(parcel.readParcelable<RemoteMessage>(RemoteMessage::class.java.classLoader)!!)
|
|
23
22
|
|
|
23
|
+
private val notificationData = NotificationData(remoteMessage.data)
|
|
24
|
+
|
|
24
25
|
override suspend fun getImage(context: Context): Bitmap? {
|
|
25
26
|
val uri = remoteMessage.notification?.imageUrl
|
|
26
27
|
return uri?.let { downloadImage(it) }
|
|
@@ -30,30 +31,20 @@ class RemoteNotificationContent(private val remoteMessage: RemoteMessage) : INot
|
|
|
30
31
|
return remoteMessage.notification?.imageUrl != null
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
override val title
|
|
34
|
-
get() = remoteMessage.notification?.title
|
|
34
|
+
override val title = remoteMessage.notification?.title ?: notificationData.title
|
|
35
35
|
|
|
36
|
-
override val text
|
|
37
|
-
get() = remoteMessage.notification?.body
|
|
36
|
+
override val text = remoteMessage.notification?.body ?: notificationData.message
|
|
38
37
|
|
|
39
|
-
override val shouldPlayDefaultSound
|
|
40
|
-
get() = remoteMessage.notification?.sound == null
|
|
38
|
+
override val shouldPlayDefaultSound = remoteMessage.notification?.sound == null && notificationData.shouldPlayDefaultSound
|
|
41
39
|
|
|
42
|
-
override val soundName
|
|
43
|
-
get() = remoteMessage.notification?.sound
|
|
40
|
+
override val soundName = remoteMessage.notification?.sound ?: notificationData.sound
|
|
44
41
|
|
|
45
42
|
override val shouldUseDefaultVibrationPattern: Boolean
|
|
46
|
-
get() = remoteMessage.notification?.defaultVibrateSettings
|
|
43
|
+
get() = remoteMessage.notification?.defaultVibrateSettings ?: notificationData.shouldUseDefaultVibrationPattern
|
|
47
44
|
|
|
48
|
-
override val vibrationPattern
|
|
49
|
-
get() = remoteMessage.notification?.vibrateTimings
|
|
45
|
+
override val vibrationPattern = remoteMessage.notification?.vibrateTimings ?: notificationData.vibrationPattern
|
|
50
46
|
|
|
51
|
-
override val body
|
|
52
|
-
get() = try {
|
|
53
|
-
remoteMessage.data["body"]?.let { JSONObject(it) }
|
|
54
|
-
} catch (e: Exception) {
|
|
55
|
-
null
|
|
56
|
-
}
|
|
47
|
+
override val body = notificationData.body
|
|
57
48
|
|
|
58
49
|
override val priority: NotificationPriority
|
|
59
50
|
get() = when (remoteMessage.priority) {
|
|
@@ -62,24 +53,23 @@ class RemoteNotificationContent(private val remoteMessage: RemoteMessage) : INot
|
|
|
62
53
|
}
|
|
63
54
|
|
|
64
55
|
override val color: Number?
|
|
65
|
-
get()
|
|
56
|
+
get() {
|
|
57
|
+
val colorSource = remoteMessage.notification?.color ?: notificationData.color
|
|
58
|
+
return colorSource?.let { android.graphics.Color.parseColor(it) }
|
|
59
|
+
}
|
|
66
60
|
|
|
67
61
|
// NOTE the following getter functions are here because the local notification content class has them
|
|
68
|
-
// and this class conforms to the same interface.
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
// and this class conforms to the same interface.
|
|
63
|
+
// They are not supported by FCM but were previously implemented by JSONNotificationContentBuilder.java.
|
|
64
|
+
override val isAutoDismiss = notificationData.autoDismiss
|
|
71
65
|
|
|
72
|
-
override val categoryId
|
|
73
|
-
get() = remoteMessage.data["categoryId"]
|
|
66
|
+
override val categoryId = notificationData.categoryId
|
|
74
67
|
|
|
75
|
-
override val isSticky
|
|
76
|
-
get() = remoteMessage.data["sticky"]?.toBoolean() ?: false
|
|
68
|
+
override val isSticky = notificationData.isSticky
|
|
77
69
|
|
|
78
|
-
override val subtitle: String?
|
|
79
|
-
get() = remoteMessage.data["subtitle"]
|
|
70
|
+
override val subtitle: String? = notificationData.subText
|
|
80
71
|
|
|
81
|
-
override val badgeCount
|
|
82
|
-
get() = remoteMessage.data["badge"]?.toIntOrNull()
|
|
72
|
+
override val badgeCount = notificationData.badge
|
|
83
73
|
|
|
84
74
|
override fun describeContents(): Int = 0
|
|
85
75
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-notifications",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.19",
|
|
4
4
|
"description": "Notifications module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"expo": "*"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "001ecb0bb73af35571b6f6429d046f552cf0ffcd"
|
|
59
59
|
}
|