From d648f306d1c20d71ee90326be05f9f7b4ebb26a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Mon, 11 Sep 2023 14:29:04 -0500 Subject: [PATCH 1/2] Add ability to set the small icon accent color --- onesignal/withOneSignalAndroid.ts | 32 ++++++++++++++++++++++++++++++- types/types.ts | 5 +++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/onesignal/withOneSignalAndroid.ts b/onesignal/withOneSignalAndroid.ts index 08fe584..bc15a06 100644 --- a/onesignal/withOneSignalAndroid.ts +++ b/onesignal/withOneSignalAndroid.ts @@ -3,7 +3,7 @@ * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps */ -import { ConfigPlugin, withDangerousMod } from '@expo/config-plugins'; +import { ConfigPlugin, withDangerousMod, withStringsXml } from '@expo/config-plugins'; import { generateImageAsync } from '@expo/image-utils'; import { OneSignalLog } from '../support/OneSignalLog'; import { OneSignalPluginProps } from '../types/types'; @@ -72,6 +72,35 @@ const withLargeIcons: ConfigPlugin = ( ]); }; +const withSmallIconAccentColor: ConfigPlugin = (config, onesignalProps) => { + if(!onesignalProps.smallIconAccentColor) { + return config + } + + return withStringsXml(config, (config) => { + const colorInARGB = `FF${onesignalProps.smallIconAccentColor?.replace('#', '')}`; + const strings = config.modResults.resources.string ?? []; + + // Check if the accent color entry already exists + const hasAccentColor = strings.some( + (stringEntry) => + stringEntry.$?.name === 'onesignal_notification_accent_color' && + stringEntry._ === colorInARGB + ); + + if (!hasAccentColor) { + const accentColorEntry = { + $: { name: 'onesignal_notification_accent_color' }, + _: colorInARGB, + }; + + config.modResults.resources.string = [...strings, accentColorEntry]; + } + + return config; + }); +} + async function saveIconsArrayAsync(projectRoot: string, icons: string[], dirsToSize: { [name: string]: number }) { for(const icon of icons) { await saveIconAsync(icon, projectRoot, dirsToSize); @@ -113,5 +142,6 @@ export const withOneSignalAndroid: ConfigPlugin = ( ) => { config = withSmallIcons(config, props); config = withLargeIcons(config, props); + config = withSmallIconAccentColor(config, props); return config; }; diff --git a/types/types.ts b/types/types.ts index ff3bc8a..ad48ac8 100644 --- a/types/types.ts +++ b/types/types.ts @@ -24,6 +24,11 @@ */ smallIcons?: string[]; + /** + * (optional) The accent color to use for notification icons on Android. Must be a valid Android color resource, for example: "#FF0000" + */ + smallIconAccentColor?: string; + /** * (optional) The large notification icons for Android. Images will be automatically scaled up/down to 256x256. */ From 8a49f8bd469c4ad400c121759b04adf29645f4fb Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Mon, 11 Sep 2023 14:33:23 -0500 Subject: [PATCH 2/2] Document change in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9f8696c..1e47b06 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ You can pass props to the plugin config object to configure: | `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"`. | | `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. | | `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. | +| `smallIconAccentColor` | optional | The accent color to use for notification icons on Android. Must be a valid hex value, e.g: `"#FF0000"` | | `iosNSEFilePath` | optional | The local path to a custom Notification Service Extension (NSE), written in Objective-C. The NSE will typically start as a copy of the [default NSE](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/support/serviceExtensionFiles/NotificationService.m), then altered to support any custom logic required. e.g: `"./assets/NotificationService.m"`. | ### OneSignal App ID