OneSignal/onesignal-expo-plugin

[question]: Set small icon accent color

dakshshah96 opened this issue · 4 comments

How can we help?

Just like how one can specify smallIcons in the app config, is it also possible to define the small icon accent color in the same place? If not, that would be a great feature to implement in this SDK.

Is there any workaround to set the accent color in the meanwhile?

OneSignal Expo SDK version

1.3.2

Platform

Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

A custom config plugin can be used as a temporary solution, based on the Android SDK documentation.

Something along these lines:

// plugins/one-signal-android-icon-accent/withOneSignalAndroidIconAccent.js

import { withStringsXml } from '@expo/config-plugins';

/**
 * A simple config plugin for One Signal that sets the push notification icon accent color on Android.
 *
 * @see {@link https://documentation.onesignal.com/docs/customize-notification-icons#set-default-small-icon-and-accent-colors} Set default Small Icon and Accent Colors
 * @see {@link https://github.com/OneSignal/onesignal-expo-plugin/issues/183} Related GitHub issue
 */
export function withOneSignalAndroidIconAccent(config, props) {
  return withStringsXml(config, (config) => {
    const colorInARGB = `FF${props.color.replace('#', '')}`;
    const strings = config.modResults.resources.string ?? [];
    const accentColorEntry = {
      $: { name: 'onesignal_notification_accent_color' },
      _: colorInARGB,
    };

    config.modResults.resources.string = [...strings, accentColorEntry];

    return config;
  });
};

export default withOneSignalAndroidIconAccent;
// app.config.js

module.exports = {
  expo: {
    // ...
    plugins: [
      ['onesignal-expo-plugin', { //... }],
      ['./plugins/one-signal-android-icon-accent/withOneSignalAndroidIconAccent.js', { color: '#e3e3e3' }]
    ]
  },
}

@karengrigoryan this is great! Could easily create a PR for this, no?

Small update: The script adds the line every time it's run no matter if it already exists or not, which isn't ideal for bare workflows (i.e. when the ios/android folders exist in the project already). Might want to add a check.

@AdamGerthel I have created a PR for this. Please feel free to test it.