oracle / pushiomanager-react-native

React Native Module for Responsys SDK
Universal Permissive License v1.0
15 stars 17 forks source link

On Android setSmallIcon when used with an XML resource adds unneeded padding, makes notification icon look incorrect. #21

Open shamilovtim opened 3 years ago

shamilovtim commented 3 years ago

Our notification icon is an XML resource. As you can see the icon is not scaled correctly and seems to have padding. When used with pure FCM push (no Responsys) the icon appears correctly and at the right size. Also it would be nice if you provided a setIconColor function (for default_notification_color) in order to style the icon for when the icon is provided in XML format. When a PNG resource is used, the icon appears correctly in Responsys. So this is an incompatibility with XML icons.

Is there a reason you can't use the default icon settings that are already passed to FCM in AndroidManifest?

The native code is as follows:

      // if it's a responsys push, set the icon and handle it with Responsys
        if (pushIOManager.isResponsysPush(remoteMessage)) {
            String appName = reactContext.getPackageName();
            int notificationIconID = reactContext.getResources().getIdentifier("ic_launcher_foreground", "drawable", appName);
            pushIOManager.setDefaultSmallIcon(notificationIconID);
            pushIOManager.setDefaultLargeIcon(notificationIconID);
            pushIOManager.handleMessage(remoteMessage);
        } else {
            // Otherwise not a Responsys push notification, handle it through FCM only
            FCMModule.onMessageReceived(reactContext, dataMap);
        }

Responsys:

Screen Shot 2021-07-21 at 3 19 10 PM Screen Shot 2021-07-21 at 3 19 18 PM

FCM:

Screen Shot 2021-07-21 at 3 21 53 PM Screen Shot 2021-07-21 at 3 21 45 PM
neerhaj commented 3 years ago

Please share the XML file that has this issue.

shamilovtim commented 3 years ago

ic_launcher_foreground.xml.zip

neerhaj commented 3 years ago

The xml you have shared is for launcher icon.

When a launcher icon xml is used as a notification icon, there is a padding added by the system.

Firebase SDK reads the icon xml as a launcher icon, so the padding is not added by the system.

Responsys SDK reads the icon xml as a notification icon, so the padding is added by the system.

There are two ways to resolve this,

  1. Don't set the small Icon in Responsys SDK. This will force the Responsys SDK to read the icon as a launcher icon. OR
  2. Create a copy of the launcher icon xml and use it as a notification icon. -- In Android Studio, go to File > New > Image Asset -- Select Icon Type as Notification Icons and Asset Type as Image. -- Pick the icon xml file in the Path entry. -- Once the icon xml is loaded, you should be able to see the extra padding added (even though Padding displays 0%). -- To remove the padding, select Trim as Yes and save the file.
shamilovtim commented 3 years ago

Just wanted to let you know the following does not work.

Don't set the small Icon in Responsys SDK. This will force the Responsys SDK to read the icon as a launcher icon.

Not setting the icon in Responsys causes a blank white circle icon. Otherwise we wouldn't be setting the icon in Responsys at all. Can you just make Responsys use the FCM / App icon from the AppManifest?

shamilovtim commented 3 years ago

Hello @neerhaj just checking back in. Any plans to allow Responsys to use the app icon like FCM does? If we don't set the icon in Responsys, it shows up as a white dot.

neerhaj commented 3 years ago

We are looking into the possible ways to allow apps to set the smallIcon. We'll get back with an update shortly.