@react-native-firebase/messaging 18.6.2 → 18.7.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -0
- package/app.plugin.js +1 -0
- package/lib/version.js +1 -1
- package/package.json +15 -4
- package/plugin/__tests__/androidPlugin.test.ts +63 -0
- package/plugin/__tests__/fixtures/application-example.ts +12 -0
- package/plugin/__tests__/fixtures/expo-config-example.ts +15 -0
- package/plugin/build/android/index.d.ts +2 -0
- package/plugin/build/android/index.js +5 -0
- package/plugin/build/android/setupFirebaseNotifationIcon.d.ts +8 -0
- package/plugin/build/android/setupFirebaseNotifationIcon.js +62 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +16 -0
- package/plugin/src/android/index.ts +3 -0
- package/plugin/src/android/setupFirebaseNotifationIcon.ts +77 -0
- package/plugin/src/index.ts +17 -0
- package/plugin/tsconfig.json +9 -0
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [18.7.1](https://github.com/invertase/react-native-firebase/compare/v18.7.0...v18.7.1) (2023-11-29)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @react-native-firebase/messaging
|
9
|
+
|
10
|
+
## [18.7.0](https://github.com/invertase/react-native-firebase/compare/v18.6.2...v18.7.0) (2023-11-28)
|
11
|
+
|
12
|
+
### Features
|
13
|
+
|
14
|
+
- **messaging:** Adding support for Firebase Messaging via Expo config plugin. ([#7369](https://github.com/invertase/react-native-firebase/issues/7369)) ([34152ed](https://github.com/invertase/react-native-firebase/commit/34152edd189bc899e85cb4ceee92d44f1175a422))
|
15
|
+
|
6
16
|
## [18.6.2](https://github.com/invertase/react-native-firebase/compare/v18.6.1...v18.6.2) (2023-11-23)
|
7
17
|
|
8
18
|
**Note:** Version bump only for package @react-native-firebase/messaging
|
package/app.plugin.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = require('./plugin/build');
|
package/lib/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
// Generated by genversion.
|
2
|
-
module.exports = '18.
|
2
|
+
module.exports = '18.7.1';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-native-firebase/messaging",
|
3
|
-
"version": "18.
|
3
|
+
"version": "18.7.1",
|
4
4
|
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
|
5
5
|
"description": "React Native Firebase - React Native Firebase provides native integration of Firebase Cloud Messaging (FCM) for both Android & iOS. FCM is a cost free service, allowing for server-device and device-device communication. The React Native Firebase Messaging module provides a simple JavaScript API to interact with FCM.",
|
6
6
|
"main": "lib/index.js",
|
@@ -8,7 +8,9 @@
|
|
8
8
|
"scripts": {
|
9
9
|
"build": "genversion --semi lib/version.js",
|
10
10
|
"build:clean": "rimraf android/build && rimraf ios/build",
|
11
|
-
"
|
11
|
+
"build:plugin": "rimraf plugin/build && tsc --build plugin",
|
12
|
+
"lint:plugin": "eslint plugin/src/*",
|
13
|
+
"prepare": "yarn run build && yarn run build:plugin"
|
12
14
|
},
|
13
15
|
"repository": {
|
14
16
|
"type": "git",
|
@@ -22,10 +24,19 @@
|
|
22
24
|
"messaging"
|
23
25
|
],
|
24
26
|
"peerDependencies": {
|
25
|
-
"@react-native-firebase/app": "18.
|
27
|
+
"@react-native-firebase/app": "18.7.1",
|
28
|
+
"expo": ">=47.0.0"
|
29
|
+
},
|
30
|
+
"devDependencies": {
|
31
|
+
"expo": "^49.0.20"
|
32
|
+
},
|
33
|
+
"peerDependenciesMeta": {
|
34
|
+
"expo": {
|
35
|
+
"optional": true
|
36
|
+
}
|
26
37
|
},
|
27
38
|
"publishConfig": {
|
28
39
|
"access": "public"
|
29
40
|
},
|
30
|
-
"gitHead": "
|
41
|
+
"gitHead": "f8b7794db23185c8a934a3e3623e996ce282c1f7"
|
31
42
|
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { describe, expect, it, jest } from '@jest/globals';
|
2
|
+
import { setFireBaseMessagingAndroidManifest } from '../src/android/setupFirebaseNotifationIcon';
|
3
|
+
import { ExpoConfig } from '@expo/config-types';
|
4
|
+
import expoConfigExample from './fixtures/expo-config-example';
|
5
|
+
import manifestApplicationExample from './fixtures/application-example';
|
6
|
+
import { ManifestApplication } from '@expo/config-plugins/build/android/Manifest';
|
7
|
+
|
8
|
+
describe('Config Plugin Android Tests', function () {
|
9
|
+
it('applies changes to app/src/main/AndroidManifest.xml with color', async function () {
|
10
|
+
const config: ExpoConfig = JSON.parse(JSON.stringify(expoConfigExample));
|
11
|
+
const manifestApplication: ManifestApplication = JSON.parse(
|
12
|
+
JSON.stringify(manifestApplicationExample),
|
13
|
+
);
|
14
|
+
setFireBaseMessagingAndroidManifest(config, manifestApplication);
|
15
|
+
expect(manifestApplication['meta-data']).toContainEqual({
|
16
|
+
$: {
|
17
|
+
'android:name': 'com.google.firebase.messaging.default_notification_icon',
|
18
|
+
'android:resource': '@drawable/notification_icon',
|
19
|
+
},
|
20
|
+
});
|
21
|
+
expect(manifestApplication['meta-data']).toContainEqual({
|
22
|
+
$: {
|
23
|
+
'android:name': 'com.google.firebase.messaging.default_notification_color',
|
24
|
+
'android:resource': '@color/notification_icon_color',
|
25
|
+
'tools:replace': 'android:resource',
|
26
|
+
},
|
27
|
+
});
|
28
|
+
});
|
29
|
+
|
30
|
+
it('applies changes to app/src/main/AndroidManifest.xml without color', async function () {
|
31
|
+
const config = JSON.parse(JSON.stringify(expoConfigExample));
|
32
|
+
const manifestApplication: ManifestApplication = JSON.parse(
|
33
|
+
JSON.stringify(manifestApplicationExample),
|
34
|
+
);
|
35
|
+
config.notification!.color = undefined;
|
36
|
+
setFireBaseMessagingAndroidManifest(config, manifestApplication);
|
37
|
+
expect(manifestApplication['meta-data']).toContainEqual({
|
38
|
+
$: {
|
39
|
+
'android:name': 'com.google.firebase.messaging.default_notification_icon',
|
40
|
+
'android:resource': '@drawable/notification_icon',
|
41
|
+
},
|
42
|
+
});
|
43
|
+
expect(manifestApplication['meta-data']).not.toContainEqual({
|
44
|
+
$: {
|
45
|
+
'android:name': 'com.google.firebase.messaging.default_notification_icon',
|
46
|
+
'android:resource': '@drawable/notification_icon_color',
|
47
|
+
'tools:replace': 'android:resource',
|
48
|
+
},
|
49
|
+
});
|
50
|
+
});
|
51
|
+
|
52
|
+
it('applies changes to app/src/main/AndroidManifest.xml without notification', async function () {
|
53
|
+
const warnSpy = jest.spyOn(console, 'warn');
|
54
|
+
const config: ExpoConfig = JSON.parse(JSON.stringify(expoConfigExample));
|
55
|
+
const manifestApplication: ManifestApplication = JSON.parse(
|
56
|
+
JSON.stringify(manifestApplicationExample),
|
57
|
+
);
|
58
|
+
config.notification = undefined;
|
59
|
+
setFireBaseMessagingAndroidManifest(config, manifestApplication);
|
60
|
+
expect(warnSpy).toHaveBeenCalled();
|
61
|
+
warnSpy.mockRestore();
|
62
|
+
});
|
63
|
+
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ManifestApplication } from '@expo/config-plugins/build/android/Manifest';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @type {import('"@expo/config-plugins/build/android/Manifest"').ManifestApplication}
|
5
|
+
*/
|
6
|
+
const manifestApplicationExample: ManifestApplication = {
|
7
|
+
$: {
|
8
|
+
'android:name': '',
|
9
|
+
},
|
10
|
+
};
|
11
|
+
|
12
|
+
export default manifestApplicationExample;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ExpoConfig } from '@expo/config-types';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @type {import('@expo/config-types').ExpoConfig}
|
5
|
+
*/
|
6
|
+
const expoConfigExample: ExpoConfig = {
|
7
|
+
name: 'FirebaseMessagingTest',
|
8
|
+
slug: 'fire-base-messaging-test',
|
9
|
+
notification: {
|
10
|
+
icon: 'IconAsset',
|
11
|
+
color: '#1D172D',
|
12
|
+
},
|
13
|
+
};
|
14
|
+
|
15
|
+
export default expoConfigExample;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.withExpoPluginFirebaseNotification = void 0;
|
4
|
+
const setupFirebaseNotifationIcon_1 = require("./setupFirebaseNotifationIcon");
|
5
|
+
Object.defineProperty(exports, "withExpoPluginFirebaseNotification", { enumerable: true, get: function () { return setupFirebaseNotifationIcon_1.withExpoPluginFirebaseNotification; } });
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { ConfigPlugin } from '@expo/config-plugins';
|
2
|
+
import { ManifestApplication } from '@expo/config-plugins/build/android/Manifest';
|
3
|
+
import { ExpoConfig } from '@expo/config-types';
|
4
|
+
/**
|
5
|
+
* Create `com.google.firebase.messaging.default_notification_icon` and `com.google.firebase.messaging.default_notification_color`
|
6
|
+
*/
|
7
|
+
export declare const withExpoPluginFirebaseNotification: ConfigPlugin;
|
8
|
+
export declare function setFireBaseMessagingAndroidManifest(config: ExpoConfig, application: ManifestApplication): ManifestApplication | ExpoConfig;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.setFireBaseMessagingAndroidManifest = exports.withExpoPluginFirebaseNotification = void 0;
|
4
|
+
const config_plugins_1 = require("@expo/config-plugins");
|
5
|
+
/**
|
6
|
+
* Determine whether a ManifestApplication has an attribute.
|
7
|
+
*/
|
8
|
+
const hasMetaData = (application, metaData) => {
|
9
|
+
return application['meta-data']?.some(item => item['$']['android:name'] === metaData);
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* Create `com.google.firebase.messaging.default_notification_icon` and `com.google.firebase.messaging.default_notification_color`
|
13
|
+
*/
|
14
|
+
const withExpoPluginFirebaseNotification = config => {
|
15
|
+
return (0, config_plugins_1.withAndroidManifest)(config, async (config) => {
|
16
|
+
// Add NS `xmlns:tools to handle boundary conditions.
|
17
|
+
config.modResults.manifest.$ = {
|
18
|
+
...config.modResults.manifest.$,
|
19
|
+
'xmlns:tools': 'http://schemas.android.com/tools',
|
20
|
+
};
|
21
|
+
const application = config.modResults.manifest.application[0];
|
22
|
+
setFireBaseMessagingAndroidManifest(config, application);
|
23
|
+
return config;
|
24
|
+
});
|
25
|
+
};
|
26
|
+
exports.withExpoPluginFirebaseNotification = withExpoPluginFirebaseNotification;
|
27
|
+
function setFireBaseMessagingAndroidManifest(config, application) {
|
28
|
+
// If the notification object is not defined, print a friendly warning
|
29
|
+
if (!config.notification) {
|
30
|
+
// This warning is important because the notification icon can only use pure white on Android. By default, the system uses the app icon as the notification icon, but the app icon is usually not pure white, so you need to set the notification icon
|
31
|
+
// eslint-disable-next-line no-console
|
32
|
+
console.warn('For Android 8.0 and above, it is necessary to set the notification icon to ensure correct display. Otherwise, the notification will not show the correct icon. For more information, visit https://docs.expo.dev/versions/latest/config/app/#notification');
|
33
|
+
return config;
|
34
|
+
}
|
35
|
+
// Defensive code
|
36
|
+
application['meta-data'] ??= [];
|
37
|
+
const metaData = application['meta-data'];
|
38
|
+
if (config.notification.icon &&
|
39
|
+
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_icon')) {
|
40
|
+
// Expo will automatically create '@drawable/notification_icon' resource if you specify config.notification.icon.
|
41
|
+
metaData.push({
|
42
|
+
$: {
|
43
|
+
'android:name': 'com.google.firebase.messaging.default_notification_icon',
|
44
|
+
'android:resource': '@drawable/notification_icon',
|
45
|
+
},
|
46
|
+
});
|
47
|
+
}
|
48
|
+
if (config.notification.color &&
|
49
|
+
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_color')) {
|
50
|
+
metaData.push({
|
51
|
+
$: {
|
52
|
+
'android:name': 'com.google.firebase.messaging.default_notification_color',
|
53
|
+
'android:resource': '@color/notification_icon_color',
|
54
|
+
// @react-native-firebase/messaging will automatically configure the notification color from the 'firebase.json' file, setting 'tools:replace' = 'android:resource' to overwrite it.
|
55
|
+
// @ts-ignore
|
56
|
+
'tools:replace': 'android:resource',
|
57
|
+
},
|
58
|
+
});
|
59
|
+
}
|
60
|
+
return application;
|
61
|
+
}
|
62
|
+
exports.setFireBaseMessagingAndroidManifest = setFireBaseMessagingAndroidManifest;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const config_plugins_1 = require("@expo/config-plugins");
|
4
|
+
const android_1 = require("./android");
|
5
|
+
/**
|
6
|
+
* A config plugin for configuring `@react-native-firebase/app`
|
7
|
+
*/
|
8
|
+
const withRnFirebaseApp = config => {
|
9
|
+
return (0, config_plugins_1.withPlugins)(config, [
|
10
|
+
// iOS
|
11
|
+
// Android
|
12
|
+
android_1.withExpoPluginFirebaseNotification,
|
13
|
+
]);
|
14
|
+
};
|
15
|
+
const pak = require('@react-native-firebase/messaging/package.json');
|
16
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withRnFirebaseApp, pak.name, pak.version);
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { ConfigPlugin, withAndroidManifest } from '@expo/config-plugins';
|
2
|
+
import { ManifestApplication } from '@expo/config-plugins/build/android/Manifest';
|
3
|
+
import { ExpoConfig } from '@expo/config-types';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Determine whether a ManifestApplication has an attribute.
|
7
|
+
*/
|
8
|
+
const hasMetaData = (application: ManifestApplication, metaData: string) => {
|
9
|
+
return application['meta-data']?.some(item => item['$']['android:name'] === metaData);
|
10
|
+
};
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Create `com.google.firebase.messaging.default_notification_icon` and `com.google.firebase.messaging.default_notification_color`
|
14
|
+
*/
|
15
|
+
export const withExpoPluginFirebaseNotification: ConfigPlugin = config => {
|
16
|
+
return withAndroidManifest(config, async config => {
|
17
|
+
// Add NS `xmlns:tools to handle boundary conditions.
|
18
|
+
config.modResults.manifest.$ = {
|
19
|
+
...config.modResults.manifest.$,
|
20
|
+
'xmlns:tools': 'http://schemas.android.com/tools',
|
21
|
+
};
|
22
|
+
|
23
|
+
const application = config.modResults.manifest.application![0];
|
24
|
+
setFireBaseMessagingAndroidManifest(config, application);
|
25
|
+
return config;
|
26
|
+
});
|
27
|
+
};
|
28
|
+
|
29
|
+
export function setFireBaseMessagingAndroidManifest(
|
30
|
+
config: ExpoConfig,
|
31
|
+
application: ManifestApplication,
|
32
|
+
) {
|
33
|
+
// If the notification object is not defined, print a friendly warning
|
34
|
+
if (!config.notification) {
|
35
|
+
// This warning is important because the notification icon can only use pure white on Android. By default, the system uses the app icon as the notification icon, but the app icon is usually not pure white, so you need to set the notification icon
|
36
|
+
// eslint-disable-next-line no-console
|
37
|
+
console.warn(
|
38
|
+
'For Android 8.0 and above, it is necessary to set the notification icon to ensure correct display. Otherwise, the notification will not show the correct icon. For more information, visit https://docs.expo.dev/versions/latest/config/app/#notification',
|
39
|
+
);
|
40
|
+
return config;
|
41
|
+
}
|
42
|
+
|
43
|
+
// Defensive code
|
44
|
+
application['meta-data'] ??= [];
|
45
|
+
|
46
|
+
const metaData = application['meta-data'];
|
47
|
+
|
48
|
+
if (
|
49
|
+
config.notification.icon &&
|
50
|
+
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_icon')
|
51
|
+
) {
|
52
|
+
// Expo will automatically create '@drawable/notification_icon' resource if you specify config.notification.icon.
|
53
|
+
metaData.push({
|
54
|
+
$: {
|
55
|
+
'android:name': 'com.google.firebase.messaging.default_notification_icon',
|
56
|
+
'android:resource': '@drawable/notification_icon',
|
57
|
+
},
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
if (
|
62
|
+
config.notification.color &&
|
63
|
+
!hasMetaData(application, 'com.google.firebase.messaging.default_notification_color')
|
64
|
+
) {
|
65
|
+
metaData.push({
|
66
|
+
$: {
|
67
|
+
'android:name': 'com.google.firebase.messaging.default_notification_color',
|
68
|
+
'android:resource': '@color/notification_icon_color',
|
69
|
+
// @react-native-firebase/messaging will automatically configure the notification color from the 'firebase.json' file, setting 'tools:replace' = 'android:resource' to overwrite it.
|
70
|
+
// @ts-ignore
|
71
|
+
'tools:replace': 'android:resource',
|
72
|
+
},
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
return application;
|
77
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { ConfigPlugin, withPlugins, createRunOncePlugin } from '@expo/config-plugins';
|
2
|
+
import { withExpoPluginFirebaseNotification } from './android';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* A config plugin for configuring `@react-native-firebase/app`
|
6
|
+
*/
|
7
|
+
const withRnFirebaseApp: ConfigPlugin = config => {
|
8
|
+
return withPlugins(config, [
|
9
|
+
// iOS
|
10
|
+
|
11
|
+
// Android
|
12
|
+
withExpoPluginFirebaseNotification,
|
13
|
+
]);
|
14
|
+
};
|
15
|
+
|
16
|
+
const pak = require('@react-native-firebase/messaging/package.json');
|
17
|
+
export default createRunOncePlugin(withRnFirebaseApp, pak.name, pak.version);
|