Conversation
Render OneSignal's custom background image notfications in RTL (right-to-left) for those devices that have set a language that renders in this direction. This does not account for some spacing issues however the next commit will cover this.
Correct the title and body 4dp padding from "left" to "start" to support both RTL and LTR languages. This panding is important so there is a bit of room between the large icon or the edge of the screen depending on if the text is LTR or RTL, in that order . Changed `layout_marginStart` to `left` since the SDK does not support a different image based on if the device is RTL or LTR. Along with this change the documenation should instruct developers to always put their app icon on the left side.
18 tasks
nan-li
approved these changes
Oct 28, 2021
Contributor
nan-li
left a comment
There was a problem hiding this comment.
Just to clarify, the second notification image has a gap on the right side - this is correct behavior right? It is because the image itself is a smaller size, creating that gap?
Base automatically changed from
fix/notification_background_image_rtl
to
main
October 28, 2021 17:59
Member
Author
|
@nan-li yes, the gap on the right is expected since the image on the 2nd notification is not very wide. Sorry it was a bad example that looks confusing. |
Jeasmine
approved these changes
Oct 28, 2021
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 layouts to render RTL text based on the device's language setting.
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_layoutin the payload.AndroidManifest.xmlhasandroid:supportsRtl="true"This PR only affects the text rendering on background image notification layout.
Out of scope:
android:textDirectionwas introduced in Android API level 17.What was the bug?
When the notification background image is set and the RTL conditions are meet, the notification text renders on the left side instead of the right side. It also renders over the left safe area (where the app icon is).
NOTE: Background image used in this example isn't the best example, an app icon should be backed into the background image, on left side.
On LTR devices notifications looks like this :

On RTL devices notifications looks like this:

Why the bug was happening?
The text elements on the notification layout had RTL disabled with
tools:ignore="RtlCompat", and didn't account for the different padding location.How the bug was fixed?
Added
android:textDirection="locale"on the layout used for the both the title and body so it's influenced by the language direction. Also corrected title and body padding to support RTL.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