UNPKG

react-native-firebase-compiled

Version:

A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto

182 lines (138 loc) 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNative = require("react-native"); var _AndroidNotification = _interopRequireDefault(require("./AndroidNotification")); var _IOSNotification = _interopRequireDefault(require("./IOSNotification")); var _utils = require("../../utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class Notification { // iOS 8/9 | 10+ | Android // alertBody | body | contentText // userInfo | userInfo | extras // soundName | sound | sound // N/A | subtitle | subText // alertTitle | title | contentTitle constructor(nativeNotification, notifications) { _defineProperty(this, "_android", void 0); _defineProperty(this, "_body", void 0); _defineProperty(this, "_data", void 0); _defineProperty(this, "_ios", void 0); _defineProperty(this, "_notificationId", void 0); _defineProperty(this, "_sound", void 0); _defineProperty(this, "_subtitle", void 0); _defineProperty(this, "_title", void 0); if (nativeNotification) { this._body = nativeNotification.body; this._data = nativeNotification.data; this._notificationId = nativeNotification.notificationId; this._sound = nativeNotification.sound; this._subtitle = nativeNotification.subtitle; this._title = nativeNotification.title; } this._android = new _AndroidNotification.default(this, nativeNotification && nativeNotification.android); this._ios = new _IOSNotification.default(this, notifications, nativeNotification && nativeNotification.ios); // Defaults this._data = this._data || {}; // TODO: Is this the best way to generate an ID? this._notificationId = this._notificationId || (0, _utils.generatePushID)(); } get android() { return this._android; } get body() { return this._body; } get data() { return this._data; } get ios() { return this._ios; } get notificationId() { return this._notificationId; } get sound() { return this._sound; } get subtitle() { return this._subtitle; } get title() { return this._title; } /** * * @param body * @returns {Notification} */ setBody(body) { this._body = body; return this; } /** * * @param data * @returns {Notification} */ setData(data = {}) { if (!(0, _utils.isObject)(data)) { throw new Error(`Notification:withData expects an object but got type '${typeof data}'.`); } this._data = data; return this; } /** * * @param notificationId * @returns {Notification} */ setNotificationId(notificationId) { this._notificationId = notificationId; return this; } /** * * @param sound * @returns {Notification} */ setSound(sound) { this._sound = sound; return this; } /** * * @param subtitle * @returns {Notification} */ setSubtitle(subtitle) { this._subtitle = subtitle; return this; } /** * * @param title * @returns {Notification} */ setTitle(title) { this._title = title; return this; } build() { if (!this._notificationId) { throw new Error('Notification: Missing required `notificationId` property'); } return { android: _reactNative.Platform.OS === 'android' ? this._android.build() : undefined, body: this._body, data: this._data, ios: _reactNative.Platform.OS === 'ios' ? this._ios.build() : undefined, notificationId: this._notificationId, sound: this._sound, subtitle: this._subtitle, title: this._title }; } } exports.default = Notification;