onesignal-expo-plugin 1.1.1 → 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.
@@ -0,0 +1,46 @@
1
+ <!-- START -->
2
+ # READ AND DELETE THIS SECTION BEFORE SUBMITTING PR
3
+ * **Fill out each _REQUIRED_ section**
4
+ * **Fill out _OPTIONAL_ sections, remove section if it doesn't apply to your PR**
5
+ * **Read and fill out each of the checklists below**
6
+ * **Remove this section after reading**
7
+ <!-- END -->
8
+
9
+ # Description
10
+ ## One Line Summary
11
+ **REQUIRED** - Very short description that summaries the changes in this PR.
12
+
13
+ ## Details
14
+
15
+ ### Motivation
16
+ **REQUIRED -** Why is this code change being made? Or what is the goal of this PR? Examples: Fixes a specific bug, provides additional logging to debug future issues, feature to allow X.
17
+
18
+ ### Scope
19
+ **RECOMMEND - OPTIONAL -** What is intended to be effected. What is known not to change. Example: Notifications are grouped when parameter X is set, not enabled by default.
20
+
21
+ ### OPTIONAL - Other
22
+ **OPTIONAL -** Feel free to add any other sections or sub-sections that can explain your PR better.
23
+
24
+ # Testing
25
+
26
+ ## Manual testing
27
+ **REQUIRED -** Explain what scenarios were tested and the environment.
28
+
29
+
30
+ # Checklist
31
+ ## Overview
32
+ - [ ] I have filled out all **REQUIRED** sections above
33
+ - [ ] PR does one thing
34
+ - If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
35
+ - [ ] Any Public API changes are explained in the PR details and conform to existing APIs
36
+
37
+ ## Testing
38
+ - [ ] I have personally tested this on my device, or explained why that is not possible
39
+ - [ ] I have tested this on the latest version of the plugin
40
+ - [ ] I have tested this on both Android and iOS, or explained why that is not possible
41
+
42
+ ## Final pass
43
+ - [ ] Code is as readable as possible.
44
+ - Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
45
+ - [ ] I have reviewed this PR myself, ensuring it meets each checklist item
46
+ - WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,28 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
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
+
11
+ ### `1.1.2` - 10/04/22
12
+ #### Fixes
13
+ - Specify `use_frameworks` on `OneSignalNotificationServiceExtension` target in iOS Podfile when applicable (i.e. the app target also specifies `use_frameworks`).
14
+
15
+ ## September 2022
16
+ ### `1.1.1` - 09/06/22
17
+ #### Fixes
18
+ - Fix issue where EAS release builds were no longer successfully building due to log statement
19
+
20
+ ### `1.1.0` - 09/01/22
21
+ #### Changes
22
+ - No longer inject the OneSignal Gradle plugin on Android builds
23
+ #### Fixes
24
+ - Fix issue where plugin does not support monorepos
25
+
4
26
  ## April 2022
5
27
  ### `1.0.1` - 04/11/22
6
28
 
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;
@@ -5,7 +5,11 @@
5
5
  */
6
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
7
  if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
9
13
  }) : (function(o, m, k, k2) {
10
14
  if (k2 === undefined) k2 = k;
11
15
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -6,6 +6,7 @@ exports.TARGETED_DEVICE_FAMILY = `"1,2"`;
6
6
  exports.NSE_PODFILE_SNIPPET = `
7
7
  target 'OneSignalNotificationServiceExtension' do
8
8
  pod 'OneSignalXCFramework', '>= 3.0', '< 4.0'
9
+ use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
9
10
  end`;
10
11
  exports.NSE_PODFILE_REGEX = /target 'OneSignalNotificationServiceExtension'/;
11
12
  exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;
@@ -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.1",
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
  }
@@ -4,6 +4,7 @@ export const TARGETED_DEVICE_FAMILY = `"1,2"`;
4
4
  export const NSE_PODFILE_SNIPPET = `
5
5
  target 'OneSignalNotificationServiceExtension' do
6
6
  pod 'OneSignalXCFramework', '>= 3.0', '< 4.0'
7
+ use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
7
8
  end`;
8
9
 
9
10
  export const NSE_PODFILE_REGEX = /target 'OneSignalNotificationServiceExtension'/;
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
  /**