Fix notification background image not showing on when the device has a RTL set #1473
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
android_background_layout
in the payload.AndroidManifest.xml
hasandroid:supportsRtl="true"
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.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:
On RTL devices notifications looks like this:
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:
Screenshot after fix
Android 10 Emulator with English with "Force RTL layout direction" enabled:
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is