Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 471d3bb

Browse files
committed
Add tests for channel update. #1549
1 parent 7a3866e commit 471d3bb

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ To use custom channels, create them at startup and pass the matching `channelId`
381381
importance: 4, // (optional) default: 4. Int value of the Android notification importance
382382
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
383383
},
384-
(created: any) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
384+
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
385385
);
386386
```
387387

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ private boolean checkOrCreateChannel(NotificationManager manager, String channel
927927
channel_description = this.config.getChannelDescription(channel_id);
928928
}
929929

930-
if (channel == null || channel.getName() != channel_name || channel.getDescription() != channel_description) {
930+
if (channel == null || !channel.getName().equals(channel_name) || !channel.getDescription().equals(channel_description)) {
931931
// If channel doesn't exist create a new one.
932932
// If channel name or description is updated then update the existing channel.
933933
channel = new NotificationChannel(channel_id, channel_name, importance);

example/App.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ export default class App extends Component {
112112
}}>
113113
<Text>Console.Log Scheduled Local Notifications</Text>
114114
</TouchableOpacity>
115+
<TouchableOpacity
116+
style={styles.button}
117+
onPress={() => {
118+
this.notif.createOrUpdateChannel();
119+
}}>
120+
<Text>Create or update a channel</Text>
121+
</TouchableOpacity>
115122

116123
<View style={styles.spacer}></View>
117124

example/NotifService.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import NotificationHandler from './NotificationHandler';
44
export default class NotifService {
55
constructor(onRegister, onNotification) {
66
this.lastId = 0;
7+
this.lastChannelCounter = 0;
78

89
NotificationHandler.attachRegister(onRegister);
910
NotificationHandler.attachNotification(onNotification);
@@ -20,6 +21,21 @@ export default class NotifService {
2021
});
2122
}
2223

24+
createOrUpdateChannel() {
25+
this.lastChannelCounter++;
26+
PushNotification.createChannel(
27+
{
28+
channelId: "custom-channel-id", // (required)
29+
channelName: `Custom channel - Counter: ${this.lastChannelCounter}`, // (required)
30+
channelDescription: `A custom channel to categorise your custom notifications. Updated at: ${Date.now()}`, // (optional) default: undefined.
31+
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
32+
importance: 4, // (optional) default: 4. Int value of the Android notification importance
33+
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
34+
},
35+
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
36+
);
37+
}
38+
2339
localNotif(soundName) {
2440
this.lastId++;
2541
PushNotification.localNotification({

example/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@
5353
android:value="Super channel description"/>
5454
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
5555
android:resource="@android:color/white"/>
56-
57-
58-
59-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.rn-push-notification-channel-id-4-300"
60-
android:value="Example-Channel silent"/>
61-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.rn-push-notification-channel-id-4-300"
62-
android:value="Super channel description for silent channel"/>
6356
</application>
6457

6558
</manifest>

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@react-native-community/push-notification-ios": "^1.2.2",
1515
"react": "16.11.0",
1616
"react-native": "0.62.2",
17-
"react-native-push-notification": "git+https://[email protected]/zo0r/react-native-push-notification.git"
17+
"react-native-push-notification": "zo0r/react-native-push-notification#dev"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.9.0",

0 commit comments

Comments
 (0)