onesignal-expo-plugin 1.1.2 → 1.2.0

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 CHANGED
@@ -2,6 +2,12 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
4
  ## October 2022
5
+ ### `1.2.0` - 10/25/22
6
+ #### Changes
7
+ - Add `smallIcons` and `largeIcons` configuration options to the plugin, which allows an app to specify large and small notification icons to package within the Android build.
8
+ - Bump jpeg-js from 0.4.3 to 0.4.4
9
+ - Bump simple-plist from 1.3.0 to 1.3.1
10
+
5
11
  ### `1.1.2` - 10/04/22
6
12
  #### Fixes
7
13
  - Specify `use_frameworks` on `OneSignalNotificationServiceExtension` target in iOS Podfile when applicable (i.e. the app target also specifies `use_frameworks`).
package/README.md CHANGED
@@ -81,9 +81,11 @@ You can pass props to the plugin config object to configure:
81
81
 
82
82
  | Plugin Prop | | |
83
83
  |--------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
84
- | `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
84
+ | `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
85
85
  | `devTeam` | optional | Used to configure Apple Team ID. You can find your Apple Team ID by running `expo credentials:manager` e.g: `"91SW8A37CR"` |
86
86
  | `iPhoneDeploymentTarget` | optional | Target `IPHONEOS_DEPLOYMENT_TARGET` value to be used when adding the iOS [NSE](https://documentation.onesignal.com/docs/service-extensions). A deployment target is nothing more than the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: `"12.0"`. |
87
+ | `smallIcons` | optional | An array of local paths to small notification icons for Android. Image should be white, transparent, and 96x96 in size. Input images will be automatically scaled down and placed in the appropriate resource folders. e.g: `["./assets/ic_stat_onesignal_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#small-notification-icons. |
88
+ | `largeIcons` | optional | An array of local paths to large notification icons for Android. Image should be white, transparent, and 256x256 in size. e.g: `["./assets/ic_onesignal_large_icon_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#large-notification-icons. |
87
89
 
88
90
  ### OneSignal App ID
89
91
  Add your OneSignal App ID to your [Expo constants via the `extra` param](https://docs.expo.dev/versions/latest/config/app/):
@@ -5,9 +5,85 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.withOneSignalAndroid = void 0;
8
+ const config_plugins_1 = require("@expo/config-plugins");
9
+ const image_utils_1 = require("@expo/image-utils");
10
+ const OneSignalLog_1 = require("../support/OneSignalLog");
11
+ const path_1 = require("path");
12
+ const fs_1 = require("fs");
13
+ const RESOURCE_ROOT_PATH = 'android/app/src/main/res/';
14
+ // The name of each small icon folder resource, and the icon size for that folder.
15
+ const SMALL_ICON_DIRS_TO_SIZE = {
16
+ 'drawable-mdpi': 24,
17
+ 'drawable-hdpi': 36,
18
+ 'drawable-xhdpi': 48,
19
+ 'drawable-xxhdpi': 72,
20
+ 'drawable-xxxhdpi': 96
21
+ };
22
+ // The name of each large icon folder resource, and the icon size for that folder.
23
+ const LARGE_ICON_DIRS_TO_SIZE = {
24
+ 'drawable-xxxhdpi': 256
25
+ };
26
+ const withSmallIcons = (config, onesignalProps) => {
27
+ var _a;
28
+ if (!onesignalProps.smallIcons && !((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon)) {
29
+ return config;
30
+ }
31
+ // we are modifying the android build (adding files) without a base mod
32
+ return (0, config_plugins_1.withDangerousMod)(config, [
33
+ 'android',
34
+ async (config) => {
35
+ var _a;
36
+ if ((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon) {
37
+ await saveIconAsync(config.notification.icon, config.modRequest.projectRoot, SMALL_ICON_DIRS_TO_SIZE);
38
+ }
39
+ if (onesignalProps.smallIcons) {
40
+ await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.smallIcons, SMALL_ICON_DIRS_TO_SIZE);
41
+ }
42
+ return config;
43
+ },
44
+ ]);
45
+ };
46
+ const withLargeIcons = (config, onesignalProps) => {
47
+ if (!onesignalProps.largeIcons) {
48
+ return config;
49
+ }
50
+ // we are modifying the android build (adding files) without a base mod
51
+ return (0, config_plugins_1.withDangerousMod)(config, [
52
+ 'android',
53
+ async (config) => {
54
+ if (onesignalProps.largeIcons) {
55
+ await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.largeIcons, LARGE_ICON_DIRS_TO_SIZE);
56
+ }
57
+ return config;
58
+ },
59
+ ]);
60
+ };
61
+ async function saveIconsArrayAsync(projectRoot, icons, dirsToSize) {
62
+ for (const icon of icons) {
63
+ await saveIconAsync(icon, projectRoot, dirsToSize);
64
+ }
65
+ }
66
+ async function saveIconAsync(icon, projectRoot, dirsToSize) {
67
+ const name = (0, path_1.parse)(icon).name;
68
+ OneSignalLog_1.OneSignalLog.log("Saving icon " + icon + " as drawable resource " + name);
69
+ for (const iconResourceDir in dirsToSize) {
70
+ const path = (0, path_1.resolve)(projectRoot, RESOURCE_ROOT_PATH, iconResourceDir);
71
+ if (!(0, fs_1.existsSync)(path)) {
72
+ (0, fs_1.mkdirSync)(path, { recursive: true });
73
+ }
74
+ const resizedIcon = (await (0, image_utils_1.generateImageAsync)({ projectRoot, cacheType: 'onesignal-icon' }, {
75
+ src: icon,
76
+ width: dirsToSize[iconResourceDir],
77
+ height: dirsToSize[iconResourceDir],
78
+ resizeMode: 'cover',
79
+ backgroundColor: 'transparent',
80
+ })).source;
81
+ (0, fs_1.writeFileSync)((0, path_1.resolve)(path, name + '.png'), resizedIcon);
82
+ }
83
+ }
8
84
  const withOneSignalAndroid = (config, props) => {
9
- //commented out until https://github.com/expo/eas-cli/issues/1226 is confirmed fixed
10
- //OneSignalLog.log("No specific actions required for OneSignal on Android...");
85
+ config = withSmallIcons(config, props);
86
+ config = withLargeIcons(config, props);
11
87
  return config;
12
88
  };
13
89
  exports.withOneSignalAndroid = withOneSignalAndroid;
@@ -3,15 +3,115 @@
3
3
  * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
4
4
  */
5
5
 
6
- import { ConfigPlugin } from '@expo/config-plugins';
6
+ import { ConfigPlugin, withDangerousMod } from '@expo/config-plugins';
7
+ import { generateImageAsync } from '@expo/image-utils';
7
8
  import { OneSignalLog } from '../support/OneSignalLog';
8
9
  import { OneSignalPluginProps } from '../types/types';
10
+ import { resolve, parse } from 'path';
11
+ import { existsSync, mkdirSync, writeFileSync } from 'fs';
12
+
13
+ const RESOURCE_ROOT_PATH = 'android/app/src/main/res/';
14
+
15
+ // The name of each small icon folder resource, and the icon size for that folder.
16
+ const SMALL_ICON_DIRS_TO_SIZE: { [name: string]: number } = {
17
+ 'drawable-mdpi': 24,
18
+ 'drawable-hdpi': 36,
19
+ 'drawable-xhdpi': 48,
20
+ 'drawable-xxhdpi': 72,
21
+ 'drawable-xxxhdpi': 96
22
+ };
23
+
24
+ // The name of each large icon folder resource, and the icon size for that folder.
25
+ const LARGE_ICON_DIRS_TO_SIZE: { [name: string]: number } = {
26
+ 'drawable-xxxhdpi': 256
27
+ };
28
+
29
+ const withSmallIcons: ConfigPlugin<OneSignalPluginProps> = (
30
+ config,
31
+ onesignalProps
32
+ ) => {
33
+
34
+ if(!onesignalProps.smallIcons && !config.notification?.icon) {
35
+ return config
36
+ }
37
+
38
+ // we are modifying the android build (adding files) without a base mod
39
+ return withDangerousMod(config, [
40
+ 'android',
41
+ async (config) => {
42
+ if(config.notification?.icon) {
43
+ await saveIconAsync(config.notification.icon, config.modRequest.projectRoot, SMALL_ICON_DIRS_TO_SIZE)
44
+ }
45
+
46
+ if(onesignalProps.smallIcons) {
47
+ await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.smallIcons, SMALL_ICON_DIRS_TO_SIZE);
48
+ }
49
+ return config;
50
+ },
51
+ ]);
52
+ };
53
+
54
+ const withLargeIcons: ConfigPlugin<OneSignalPluginProps> = (
55
+ config,
56
+ onesignalProps
57
+ ) => {
58
+
59
+ if(!onesignalProps.largeIcons) {
60
+ return config
61
+ }
62
+
63
+ // we are modifying the android build (adding files) without a base mod
64
+ return withDangerousMod(config, [
65
+ 'android',
66
+ async (config) => {
67
+ if(onesignalProps.largeIcons) {
68
+ await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.largeIcons, LARGE_ICON_DIRS_TO_SIZE);
69
+ }
70
+ return config;
71
+ },
72
+ ]);
73
+ };
74
+
75
+ async function saveIconsArrayAsync(projectRoot: string, icons: string[], dirsToSize: { [name: string]: number }) {
76
+ for(const icon of icons) {
77
+ await saveIconAsync(icon, projectRoot, dirsToSize);
78
+ }
79
+ }
80
+
81
+ async function saveIconAsync(icon: string, projectRoot: string, dirsToSize: { [name: string]: number }) {
82
+ const name = parse(icon).name;
83
+
84
+ OneSignalLog.log("Saving icon " + icon + " as drawable resource " + name);
85
+
86
+ for(const iconResourceDir in dirsToSize) {
87
+ const path = resolve(projectRoot, RESOURCE_ROOT_PATH, iconResourceDir);
88
+
89
+ if(!existsSync(path)) {
90
+ mkdirSync(path, { recursive: true });
91
+ }
92
+
93
+ const resizedIcon = (
94
+ await generateImageAsync(
95
+ { projectRoot, cacheType: 'onesignal-icon' },
96
+ {
97
+ src: icon,
98
+ width: dirsToSize[iconResourceDir],
99
+ height: dirsToSize[iconResourceDir],
100
+ resizeMode: 'cover',
101
+ backgroundColor: 'transparent',
102
+ }
103
+ )
104
+ ).source;
105
+
106
+ writeFileSync(resolve(path, name + '.png'), resizedIcon);
107
+ }
108
+ }
9
109
 
10
110
  export const withOneSignalAndroid: ConfigPlugin<OneSignalPluginProps> = (
11
111
  config,
12
112
  props,
13
113
  ) => {
14
- //commented out until https://github.com/expo/eas-cli/issues/1226 is confirmed fixed
15
- //OneSignalLog.log("No specific actions required for OneSignal on Android...");
114
+ config = withSmallIcons(config, props);
115
+ config = withLargeIcons(config, props);
16
116
  return config;
17
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onesignal-expo-plugin",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.",
5
5
  "main": "./app.plugin.js",
6
6
  "scripts": {
@@ -41,6 +41,7 @@
41
41
  "typescript": "^4.5.5"
42
42
  },
43
43
  "dependencies": {
44
- "xcode": "^3.0.1"
44
+ "xcode": "^3.0.1",
45
+ "@expo/image-utils": "^0.3.22"
45
46
  }
46
47
  }
package/types/types.ts CHANGED
@@ -3,11 +3,31 @@
3
3
  */
4
4
  export type OneSignalPluginProps = {
5
5
  /**
6
- * (iOS only) Environment name and bundle identifier
6
+ * (required) Used to configure APNs environment entitlement. "development" or "production"
7
7
  */
8
8
  mode: Mode;
9
+
10
+ /**
11
+ * (optional) Used to configure Apple Team ID. You can find your Apple Team ID by running expo credentials:manager e.g: "91SW8A37CR"
12
+ */
9
13
  devTeam: string;
14
+
15
+ /**
16
+ * (optional) Target IPHONEOS_DEPLOYMENT_TARGET value to be used when adding the iOS NSE. A deployment target is nothing more than
17
+ * the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: "12.0".
18
+ */
10
19
  iPhoneDeploymentTarget: string;
20
+
21
+ /**
22
+ * (optional) The small notification icons for Android. Images will be automatically scaled up/down, the recommended size
23
+ * is 96x96 to always scale down.
24
+ */
25
+ smallIcons?: string[];
26
+
27
+ /**
28
+ * (optional) The large notification icons for Android. Images will be automatically scaled up/down to 256x256.
29
+ */
30
+ largeIcons?: string[];
11
31
  };
12
32
 
13
33
  /**