OneSignal / onesignal-expo-plugin

The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
Other
153 stars 49 forks source link

[question]: Set small icon accent color #183

Closed dakshshah96 closed 1 year ago

dakshshah96 commented 1 year ago

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

karengrigoryan commented 1 year ago

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' }]
    ]
  },
}
AdamGerthel commented 1 year ago

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

AdamGerthel commented 1 year ago

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.

rgomezp commented 1 year ago

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