mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-04 20:11:33 +08:00
[notifications] Continue android implementation
This commit is contained in:
@@ -4,16 +4,19 @@
|
||||
*/
|
||||
import AndroidNotification from './AndroidNotification';
|
||||
import IOSNotification from './IOSNotification';
|
||||
import { isObject } from '../../utils';
|
||||
import { generatePushID, isObject } from '../../utils';
|
||||
|
||||
import type { NativeAndroidNotification } from './AndroidNotification';
|
||||
import type { NativeIOSNotification } from './IOSNotification';
|
||||
import type { Schedule } from './';
|
||||
|
||||
type NativeNotification = {|
|
||||
android: NativeAndroidNotification,
|
||||
body: string,
|
||||
data: { [string]: string },
|
||||
ios: NativeIOSNotification,
|
||||
notificationId: string,
|
||||
schedule?: Schedule,
|
||||
sound?: string,
|
||||
subtitle?: string,
|
||||
title: string,
|
||||
@@ -25,6 +28,7 @@ export default class Notification {
|
||||
_body: string; // alertBody | body | contentText
|
||||
_data: { [string]: string }; // userInfo | userInfo | extras
|
||||
_ios: IOSNotification;
|
||||
_notificationId: string;
|
||||
_sound: string | void; // soundName | sound | sound
|
||||
_subtitle: string | void; // N/A | subtitle | subText
|
||||
_title: string; // alertTitle | title | contentTitle
|
||||
@@ -33,6 +37,8 @@ export default class Notification {
|
||||
this._android = new AndroidNotification(this);
|
||||
this._data = {};
|
||||
this._ios = new IOSNotification(this);
|
||||
// TODO: Is this the best way to generate an ID?
|
||||
this._notificationId = generatePushID();
|
||||
}
|
||||
|
||||
get android(): AndroidNotification {
|
||||
@@ -68,6 +74,16 @@ export default class Notification {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param notificationId
|
||||
* @returns {Notification}
|
||||
*/
|
||||
setNotificationId(notificationId: string): Notification {
|
||||
this._notificationId = notificationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sound
|
||||
@@ -101,9 +117,13 @@ export default class Notification {
|
||||
build(): NativeNotification {
|
||||
// Android required fields: body, title, smallicon
|
||||
// iOS required fields: TODO
|
||||
if (!this.body) {
|
||||
if (!this._body) {
|
||||
throw new Error('Notification: Missing required `body` property');
|
||||
} else if (!this.title) {
|
||||
} else if (!this._notificationId) {
|
||||
throw new Error(
|
||||
'Notification: Missing required `notificationId` property'
|
||||
);
|
||||
} else if (!this._title) {
|
||||
throw new Error('Notification: Missing required `title` property');
|
||||
}
|
||||
|
||||
@@ -112,6 +132,7 @@ export default class Notification {
|
||||
body: this._body,
|
||||
data: this._data,
|
||||
ios: this._ios.build(),
|
||||
notificationId: this._notificationId,
|
||||
sound: this._sound,
|
||||
subtitle: this._subtitle,
|
||||
title: this._title,
|
||||
|
||||
Reference in New Issue
Block a user