Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notification background image not showing on when the device has a RTL set #1473

Merged
merged 1 commit into from
Oct 28, 2021

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Oct 28, 2021

Description

One Line Summary

Fix notification background image not showing on when the device has a RTL language set and the app's AndroidManifest.xml has RTL support enabled.

Details

Motivation

Setting a custom background image for notifications is a supported feature only through the REST API, is limited in features, and Android 12 has limited customizability. However OneSignal currently supports this feature and it should remind free of common/high impact bugs.

Scope

Only affects the display of notifications when the following is true:

  • Sent through the OneSignal REST API
  • Includes android_background_layout in the payload.
  • The AndroidManifest.xml has android:supportsRtl="true"
  • The device has set a RTL language
    • Or Dev options > Drawing > "Force RTL layout direction" is enabled

This PR only affects the background image render. Changes / fixes to the title or body text is out of scope for this PR.

Android 4.1 (API 16) is out of scope, since android:layoutDirection was introduced in Android API level 17.

  • This might be ok, as this issue may not have existed on this version of android anyway.

What was the bug?

When the a notification background image is set and the RTL conditions are meet, notifications becoming a sold color (all known instances have been a white background). The text may or not be visible, but depends on the text color and that the resulting background.

On LTR devices notifications looks like this:
image

On RTL devices notifications looks like this:
image

Why the bug was happening?

When RTL is set it moves all elements to the right, not just text elements.

How the bug was fixed?

Set android:layoutDirection="ltr" on the layout used for the background image so it isn't influenced by the language direction.

Testing

Unit testing

N/A, only a visual layout change.

Manual testing

Tested the Example app included in this repo (it has android:supportsRtl="true") and set "Force RTL layout direction" on the device. Also tested w/o "Force RTL layout direction", to make sure it remained working.
Test on:

  • LG G7 with Android 9
  • Android 10 Emulator
  • Android 5.0 Emulator

Screenshot after fix

Android 10 Emulator with English with "Force RTL layout direction" enabled:
image

  • Odd resized image on the 2nd notification was indented, was done as a quick size test
  • Text itself didn't change RTL, but not in this scope of this PR.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • 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
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • 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.

This change is Reviewable

The notification background image would not show if the app has
`android:supportsRtl="true"` the `AndroidManifest.xml` AND the device
has a RTL language set. This would result in the notification becoming
a sold color (all known instances have been a white background) and only
 the title and body text showing.

Setting `android:layoutDirection="ltr"` ensures the layout, only used
for images, isn't influenced by the language direction.

This does NOT affect most notifications, only those that use
`android_background_layout` in their notification payload.

This change does NOT affect the rending of the title or body text in any
way.
Copy link
Contributor

@nan-li nan-li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @adamschlesinger and @emawby)

Copy link
Contributor

@nan-li nan-li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @adamschlesinger and @emawby)

@jkasten2 jkasten2 merged commit fe84b98 into main Oct 28, 2021
@jkasten2 jkasten2 deleted the fix/notification_background_image_rtl branch October 28, 2021 17:59
@jkasten2 jkasten2 mentioned this pull request Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants