expo-notifications 0.29.9 → 0.29.10
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/NotificationContent.java +10 -0
- package/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.kt +39 -25
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 0.29.10 — 2024-12-02
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- [android] fix notifications with custom sounds treated as silent ([#33311](https://github.com/expo/expo/pull/33311) by [@pennersr](https://github.com/pennersr))
|
|
18
|
+
|
|
13
19
|
## 0.29.9 — 2024-11-29
|
|
14
20
|
|
|
15
21
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
|
|
|
2
2
|
apply plugin: 'kotlin-parcelize'
|
|
3
3
|
|
|
4
4
|
group = 'host.exp.exponent'
|
|
5
|
-
version = '0.29.
|
|
5
|
+
version = '0.29.10'
|
|
6
6
|
|
|
7
7
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
8
8
|
apply from: expoModulesCorePlugin
|
|
@@ -15,7 +15,7 @@ android {
|
|
|
15
15
|
namespace "expo.modules.notifications"
|
|
16
16
|
defaultConfig {
|
|
17
17
|
versionCode 21
|
|
18
|
-
versionName '0.29.
|
|
18
|
+
versionName '0.29.10'
|
|
19
19
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -22,6 +22,7 @@ import java.io.Serializable;
|
|
|
22
22
|
import androidx.annotation.NonNull;
|
|
23
23
|
import androidx.annotation.Nullable;
|
|
24
24
|
|
|
25
|
+
import androidx.annotation.VisibleForTesting;
|
|
25
26
|
import expo.modules.notifications.notifications.enums.NotificationPriority;
|
|
26
27
|
import expo.modules.notifications.notifications.interfaces.INotificationContent;
|
|
27
28
|
import kotlin.coroutines.Continuation;
|
|
@@ -320,6 +321,15 @@ public class NotificationContent implements Parcelable, Serializable, INotificat
|
|
|
320
321
|
return this;
|
|
321
322
|
}
|
|
322
323
|
|
|
324
|
+
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
|
325
|
+
Builder disableVibrations() {
|
|
326
|
+
// remote notifications can come without vibrations
|
|
327
|
+
// we use this method do emulate that in tests
|
|
328
|
+
content.mShouldUseDefaultVibrationPattern = false;
|
|
329
|
+
content.mVibrationPattern = null;
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
|
|
323
333
|
public Builder setVibrationPattern(long[] vibrationPattern) {
|
|
324
334
|
content.mShouldUseDefaultVibrationPattern = false;
|
|
325
335
|
content.mVibrationPattern = vibrationPattern;
|
|
@@ -5,6 +5,7 @@ import android.content.Context
|
|
|
5
5
|
import android.content.pm.PackageManager
|
|
6
6
|
import android.graphics.Bitmap
|
|
7
7
|
import android.graphics.BitmapFactory
|
|
8
|
+
import android.os.Build
|
|
8
9
|
import android.os.Bundle
|
|
9
10
|
import android.os.Parcel
|
|
10
11
|
import android.provider.Settings
|
|
@@ -13,6 +14,7 @@ import androidx.core.app.NotificationCompat
|
|
|
13
14
|
import androidx.core.app.RemoteInput
|
|
14
15
|
import expo.modules.notifications.notifications.SoundResolver
|
|
15
16
|
import expo.modules.notifications.notifications.enums.NotificationPriority
|
|
17
|
+
import expo.modules.notifications.notifications.interfaces.INotificationContent
|
|
16
18
|
import expo.modules.notifications.notifications.model.NotificationAction
|
|
17
19
|
import expo.modules.notifications.notifications.model.NotificationCategory
|
|
18
20
|
import expo.modules.notifications.notifications.model.NotificationRequest
|
|
@@ -110,31 +112,7 @@ open class ExpoNotificationBuilder(
|
|
|
110
112
|
notificationContent.badgeCount?.toInt()?.let { builder.setNumber(it) }
|
|
111
113
|
notificationContent.categoryId?.let { addActionsToBuilder(builder, it) }
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
if (shouldPlayDefaultSound && shouldVibrate()) {
|
|
115
|
-
builder.setDefaults(NotificationCompat.DEFAULT_ALL) // set sound, vibration and lights
|
|
116
|
-
} else if (shouldVibrate()) {
|
|
117
|
-
builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
|
|
118
|
-
} else if (shouldPlayDefaultSound) {
|
|
119
|
-
builder.setDefaults(NotificationCompat.DEFAULT_SOUND)
|
|
120
|
-
} else {
|
|
121
|
-
// Notification will not vibrate or play sound, regardless of channel
|
|
122
|
-
builder.setSilent(true)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (shouldPlaySound() && content.soundName != null) {
|
|
126
|
-
content.soundName?.let { soundName ->
|
|
127
|
-
val soundUri = SoundResolver(context).resolve(soundName)
|
|
128
|
-
builder.setSound(soundUri)
|
|
129
|
-
}
|
|
130
|
-
} else if (shouldPlayDefaultSound) {
|
|
131
|
-
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
val vibrationPatternOverride = content.vibrationPattern
|
|
135
|
-
if (shouldVibrate() && vibrationPatternOverride != null) {
|
|
136
|
-
builder.setVibrate(vibrationPatternOverride)
|
|
137
|
-
}
|
|
115
|
+
applySoundsAndVibrations(content, builder)
|
|
138
116
|
|
|
139
117
|
if (content.body != null) {
|
|
140
118
|
// Add body - JSON data - to extras
|
|
@@ -178,6 +156,42 @@ open class ExpoNotificationBuilder(
|
|
|
178
156
|
return builder.build()
|
|
179
157
|
}
|
|
180
158
|
|
|
159
|
+
private fun applySoundsAndVibrations(content: INotificationContent, builder: NotificationCompat.Builder) {
|
|
160
|
+
val shouldPlaySound = shouldPlaySound()
|
|
161
|
+
val shouldVibrate = shouldVibrate()
|
|
162
|
+
|
|
163
|
+
if (!shouldPlaySound && !shouldVibrate) {
|
|
164
|
+
// Notification will not vibrate or play sound, regardless of channel
|
|
165
|
+
builder.setSilent(true)
|
|
166
|
+
}
|
|
167
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
168
|
+
// the calls below are ignored on Android O and newer because the sound and vibration are set in the channel
|
|
169
|
+
val shouldPlayDefaultSound = shouldPlaySound && content.shouldPlayDefaultSound
|
|
170
|
+
val shouldUseDefaultVibrationPattern = shouldVibrate && content.shouldUseDefaultVibrationPattern
|
|
171
|
+
if (shouldUseDefaultVibrationPattern && shouldPlayDefaultSound) {
|
|
172
|
+
builder.setDefaults(NotificationCompat.DEFAULT_ALL)
|
|
173
|
+
} else {
|
|
174
|
+
if (shouldPlaySound) {
|
|
175
|
+
if (content.soundName != null) {
|
|
176
|
+
val soundUri = SoundResolver(context).resolve(content.soundName)
|
|
177
|
+
builder.setSound(soundUri)
|
|
178
|
+
} else if (shouldPlayDefaultSound) {
|
|
179
|
+
builder.setDefaults(NotificationCompat.DEFAULT_SOUND)
|
|
180
|
+
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (shouldVibrate) {
|
|
184
|
+
val vibrationPatternOverride = content.vibrationPattern
|
|
185
|
+
if (vibrationPatternOverride != null) {
|
|
186
|
+
builder.setVibrate(vibrationPatternOverride)
|
|
187
|
+
} else if (shouldUseDefaultVibrationPattern) {
|
|
188
|
+
builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
181
195
|
/**
|
|
182
196
|
* Marshalls [NotificationRequest] into to a byte array.
|
|
183
197
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-notifications",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.10",
|
|
4
4
|
"description": "Provides an API to fetch push notification tokens and to present, schedule, receive, and respond to notifications.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"react": "*",
|
|
56
56
|
"react-native": "*"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "bc1fea6bcab47889e2922d543920397691b200f3"
|
|
59
59
|
}
|